Skip to content

Instantly share code, notes, and snippets.

View thluiz's full-sized avatar

Thiago Luiz Silva thluiz

View GitHub Profile
@thluiz
thluiz / f#_convert_UInt32_to_binary
Last active December 12, 2016 15:11
Convert a UInt32 (Unsigned Integer) to Binary in F#
let rec to_binary(value: UInt32)=
if value < 2u then
value.ToString()
else
let divisor = value/2u
let remainder = (value % 2u).ToString()
to_binary(divisor) + remainder
@thluiz
thluiz / fibonacci.ex
Created February 2, 2015 09:45
The simplest fibonacci implementation
defmodule Fibonacci do
def calc(0), do: 1
def calc(1), do: 1
def calc(n) when n > 0, do: calc(n-2) + calc(n-1)
end
@thluiz
thluiz / httpoison_post_form_request.ex
Created February 1, 2015 21:51
HTTPoison post url encoded form
headers = [
{"Content-Type", "application/x-www-form-urlencoded"},
{"Accept", "text/html"}
]
encoded_text = URI.encode_www_form(text)
body = "text=#{encoded_text}"
case HTTPoison.post(url, body, headers) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
@thluiz
thluiz / httpoison_post_request.ex
Last active August 29, 2015 14:14
Making a HTTPoison post request in Elixir
case HTTPoison.post(url, body, headers) do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
body
{:ok, %HTTPoison.Response{status_code: 404}} ->
"Not found :("
{:error, %HTTPoison.Error{reason: reason}} ->
reason
end
@thluiz
thluiz / file_encoder.py
Last active April 28, 2024 06:51
Just a short python script to convert a file from one encoding to another
# coding=utf-8
"""
Convert a file from one encoder to another
usage: python file_encoder.py 'source encode', 'target encode',
'source file', 'target'
example: python file_encoder.py 'iso8859-1', 'utf-8', 'file.html',
'file-utf8.html'
"""
import sys
@thluiz
thluiz / shellNode.js
Created October 4, 2012 00:08
Run shell commands via NodeJS
var exec = require('child_process').exec;
var child = exec("echo 'teste'",
function (error, stdout, stderr) {
if(stdout!==''){
console.log('---------stdout: ---------\n' + stdout);
}
if(stderr!==''){
console.log('---------stderr: ---------\n' + stderr);