Skip to content

Instantly share code, notes, and snippets.

View fenollp's full-sized avatar

Pierre Fenoll fenollp

View GitHub Profile
@fenollp
fenollp / install_homebrew.rb
Created August 14, 2011 00:03 — forked from mxcl/install_homebrew.markdown
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
#!/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/sceaga/homebrew/tarball/tiger anywhere you like.
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end
@fenollp
fenollp / string_splitting.c
Last active December 15, 2015 01:59
A use case of strtok_r (instead of strtok) to split a string str wrt ifs characters.
char **ifs_split(const char *str, const char *ifs)
{
size_t index = 0;
size_t size = 1;
char *segment = NULL;
char *start = NULL;
char *rest = NULL;
char **tab = NULL; // Thou shall free thee.
start = dupstr(str);
-module(my_tests).
-include_lib("eunit/include/eunit.hrl").
e_test () ->
{setup, fun () -> ok end,
fun () -> ok end,
fun () -> {inorder, [
?_assertMatch(fail, hard) %% Does not fail!
]} end}.
@fenollp
fenollp / otp_vsn.erl
Created October 24, 2013 13:55
Get an easily comparable version number of Erlang/OTP at runtime.
otp_vsn () ->
R = fun (D, U) -> 10 * (D - $0) + U - $0 end,
case erlang:system_info(otp_release) of
[$R, D,U ] -> R(D,U) + 0.00;
[$R, D,U, $A ] -> R(D,U) + 0.01;
[$R, D,U, $B ] -> R(D,U) + 0.02;
[$R, D,U, $B, DD,UU] -> R(D,U) + R(DD,UU) / 10 + 0.00
end.
%% On R16B02: otp_vsn() = 16.2
@fenollp
fenollp / keyfold.erl
Created November 12, 2013 16:10
%% keyfold: extension to stdlib's lists module. %% Intersection of lists:fold{l,r}/3 and lists:keymap/3.
%% Copyright © 2013 Pierre Fenoll ‹pierrefenoll@gmail.com›
%% See LICENSE for licensing information.
%% -*- coding: utf-8 -*-
-module(keyfold).
%% keyfold: extension to stdlib's lists module.
%% Intersection of lists:fold{l,r}/3 and lists:keymap/3.
-include_lib("eunit/include/eunit.hrl").
%% Copyright © 2013 Pierre Fenoll ‹pierrefenoll@gmail.com›
%% See LICENSE for licensing information.
%% -*- coding: utf-8 -*-
-module(ifdef_in_fun).
%% 12:40 < stobix>| Grr... It would seem that I can't use ifdef directives inside function bodies. Any reason why, or is it just a design flaw?
%% 1> c(ifdef_in_fun).
%% ifdef_in_fun.erl:16: syntax error before: '-'
%% ifdef_in_fun.erl:18: syntax error before: '-'
-module(thear).
-export([simplify/1]).
-spec simplify (E) -> E when E::term().
simplify (E) ->
S = fun
({add,E1,{num,0}}) ->
S(E1);
# For rπ only: -march=armv6zk -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard
git clone git@github.com:ckolivas/cgminer.git cgminer.git
cd cgminer.git/
git checkout v4.2.3 # The latest
./autogen.sh
CFLAGS="-O2 -Wall -march=armv6zk -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard" ./configure --enable-bflsc
CXXFLAGS="-O2 -Wall -march=armv6zk -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard" make
sudo ./cgminer -o stratum+tcp://eu-stratum.btcguild.com:3333 -u radioxid_monolith -p 123b
-module(propfolding).
-export([get/1]).
get (Doc) ->
{Stars, AreaID, CheckinDate, HotelID, Rooms} =
lists:foldl(
fun
({<<"stars">>, Stars}, Acc) -> setelement(1, Acc, Stars);
({<<"areaID">>, AreaID}, Acc) -> setelement(2, Acc, AreaID);
({<<"checkinDate">>, <<Year:4, $-, Month:2, $-, Day:2>>}, Acc) ->
@fenollp
fenollp / wat_clauses
Created April 1, 2015 17:48
Erlang not good with strings
%% -*- coding: utf-8 -*-
-module(wat_clauses).
%% wat_clauses:
%% a warning should be emitted as 2nd clause will never match (given 1st clause)
-export([authenticate_nouns/1]).
%% API