Skip to content

Instantly share code, notes, and snippets.

View l1x's full-sized avatar
🏠
Working from home

Istvan l1x

🏠
Working from home
View GitHub Profile
@l1x
l1x / tut.erl
Created February 1, 2011 21:52
tutrial
run() ->
Pid = spawn(fun ping/0),
Pid ! self(),
receive
pong -> ok
end.
ping() ->
receive
From -> From ! pong
end.
@l1x
l1x / yaml generator
Created February 2, 2011 21:52
generating test.yml
require 'rubygems'
require 'bcrypt'
require 'digest/md5'
require 'yaml'
#todo
# load schema.rb
# t.string "username", :limit => 30
# t.string "email"
@l1x
l1x / sample
Created February 5, 2011 11:07
user
---
990:
:updated_at: 2011-02-03 15:17:10.704334 +00:00
:email: archpresbytery@gmail.com
:karma: 5
:password_salt: $2a$10$31sLwM64th6X07yLN5nw/e
:sign_in_count: 2
:password_hash: $2a$10$31sLwM64th6X07yLN5nw/eK8rzfBn8ofFEbrve8dU9OiwKmmaxbd2
:sign_in_failed: 2
:reset_password_token: asd
@l1x
l1x / gist:814186
Created February 7, 2011 09:39
ruby disable pthreads
WITHOUT_PTHREADS= yes
.if defined(WITHOUT_PTHREADS)
CONFIGURE_ARGS+=--disable-pthread
PKGNAMESUFFIX:= ${PKGNAMESUFFIX}+nopthreads
.else
LDFLAGS+= ${PTHREAD_LIBS}
CONFIGURE_ARGS+=--disable-pthread
.endif
@l1x
l1x / rails.rb
Created February 13, 2011 21:15
rails test
Nohup::Application.routes.draw do
namespace "admin" do
get "users/:id/edit" => "users#edit"
get "users/:id" => "users#show"
get "users" => "users#index"
put "users" => "users#index"
#resources :comments, :only => [:create, :destroy]
end
@l1x
l1x / nested_hashes.rb
Created February 13, 2011 23:29
Nested Hashes with Symbols
#/usr/bin/env ruby
silicates = Hash.new {
|h, k| h[k] = Hash.new
}
silicates[:mineral0]["ruby"] = "String + red"
silicates[:mineral1]["ruby"] = "String + blue"
silicates[:mineral2][:ruby] = "Symbol + green"
silicates[:mineral3][:ruby] = "Symbol + black"
@l1x
l1x / inet.hrl
Created February 20, 2011 23:41
inet in erlang
-type hostname() :: atom() | string().
-type ip4_address() :: {0..255,0..255,0..255,0..255}.
-type ip6_address() :: {0..65535,0..65535,0..65535,0..65535,
0..65535,0..65535,0..65535,0..65535}.
-type ip_address() :: ip4_address() | ip6_address().
-type ip_port() :: 0..65535.
-record(hostent,
{
h_name :: hostname(), %% offical name of host
@l1x
l1x / lists.erl
Created February 20, 2011 23:55
map function
-spec map(fun((D) -> R), [D]) -> [R].
map(F, [H|T]) ->
[F(H)|map(F, T)];
map(F, []) when is_function(F, 1) -> [].
@l1x
l1x / mnesia:transaction.erl
Created February 23, 2011 21:14
how to handle a transaction with mnesia
{atomic, Result} = mnesia:transaction(Fun)
case Result of [] -> undefined [Rec] -> Rec#rec.prop end.
%% http://www.erlang.org/doc/man/mnesia.html#transaction-2
add_family({family, F, M, Children}) ->
ChildOids = lists:map(fun oid/1, Children),
Trans = fun() ->
mnesia:write(F#person{children = ChildOids},
mnesia:write(M#person{children = ChildOids},
Write = fun(Child) -> mnesia:write(Child) end,
@l1x
l1x / gist:866032
Created March 11, 2011 15:35
is this valid?
class X
def initialize
begin
@yaml_hash = YAML::load(File.read("xyz.yml"))
rescue => e
puts "An error generated during opening the xyz.yml"
puts e
end
end
end