Skip to content

Instantly share code, notes, and snippets.

View lucca65's full-sized avatar

Julien Lucca lucca65

View GitHub Profile
@lucca65
lucca65 / bitbucket-import.rb
Last active August 29, 2015 14:27 — forked from uri/bitbucket-import.rb
Import public repos from Bitbucket to Github
require 'httparty'
class Github
include HTTParty
base_uri "https://api.github.com"
BaseDirectory = "/Users/ugorelik/programming/repos"
def initialize(u, p)
@auth = { username: u, password: p}
load_bitbucket_repos
@lucca65
lucca65 / tiago_davi.exs
Created August 20, 2015 14:46
Gist fixing Tiago Davi code
defmodule Tax do
def get_tax_rates do
[ NC: 0.075, TX: 0.08 ]
end
def get_orders do
[
[ id: 123, ship_to: :NC, net_amount: 100.00 ],
[ id: 124, ship_to: :OK, net_amount: 35.50 ],
[ id: 125, ship_to: :TX, net_amount: 24.00 ],
[ id: 126, ship_to: :TX, net_amount: 44.80 ],
defmodule Test do
def create(conn, params) do
params
|> do_register # do business logic
|> format_response(conn) # create the message
|> render_json # just render it, simple, elegant
end
# toda funcao no elixir retorna alguma coisa, não existe `void`
defp do_register(params) do
(defun safadao ()
(interactive) ;; interactive interpreter
(let (birthdate) ;; create variable birthdate, it will be avaliable for nested stuff
(progn (setq birthdate (read-no-blanks-input "digite sua data de nascimento: "))) ;; set birthdate to whatever user inputs
(if (and (< 7 (length birthdate))
(> 9 (length birthdate)))
(let ((sum 0) list day month year safadeza)
(progn
(setq list (split-string birthdate "/"))
# encoding: UTF-8
require 'rubygems'
require 'csv'
require 'geocoder'
ips = CSV.read('ip.csv')
total = ips.length
decoded_ips = []
/*
* DO NOT COMPILE AND RUN UNLESS YOU KNOW WHAT YOU ARE DOING.
* This is a 29 byte C code that compiles to a 17,179,875,837 byte (16 GB) executable.
* Author: Digital Trauma (codegolf.stackexchange.com/users/11259/digital-trauma)
* This defines the main function as a large array and initialises its first element.
* This causes GCC to store the entire array in the resulting executable.
* Because this array is bigger than 2GB,
* we need to provide the -mcmodel=medium flag to GCC.
* The extra 15 bytes are included in the score, as per the rules.
* Compile with:
@lucca65
lucca65 / word_list.exs
Created December 7, 2016 19:46
Word list problem Elixir implementation
defmodule WordFreq.Parser do
def work do
read_file
|> to_list
|> group
|> transform
|> Enum.take(10)
end
@doc """
@lucca65
lucca65 / client.exs
Last active December 7, 2016 19:55
Prime number simple cluster implementation
defmodule Worker do
def start do
pid = spawn(__MODULE__, :loop, [])
send(server_pid, {:request, pid})
pid
end
def server_pid do
:global.whereis_name("server")
end
@lucca65
lucca65 / network_fail_handler.ex
Created March 10, 2017 02:20
Gen server that handle nerves nodes changing its IP and updates its node name
defmodule MyApp.DistributionManager do
use GenServer
require Logger
@app Mix.Project.config[:app]
def start_link(iface) do
GenServer.start_link(__MODULE__, iface)
end
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
const int MAX_N = 510;
const int MAX_K = 510;
int N, K;