Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Istvan l1x

🏠
Working from home
View GitHub Profile
View tut.erl
run() ->
Pid = spawn(fun ping/0),
Pid ! self(),
receive
pong -> ok
end.
ping() ->
receive
From -> From ! pong
end.
@l1x
l1x / yaml generator
Created Feb 2, 2011
generating test.yml
View yaml generator
require 'rubygems'
require 'bcrypt'
require 'digest/md5'
require 'yaml'
#todo
# load schema.rb
# t.string "username", :limit => 30
# t.string "email"
View sample
---
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 Feb 7, 2011
ruby disable pthreads
View gist:814186
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 Feb 13, 2011
rails test
View rails.rb
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 Feb 13, 2011
Nested Hashes with Symbols
View nested_hashes.rb
#/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 Feb 20, 2011
inet in erlang
View inet.hrl
-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 Feb 20, 2011
map function
View lists.erl
-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 Feb 23, 2011
how to handle a transaction with mnesia
View mnesia:transaction.erl
{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 Mar 11, 2011
is this valid?
View gist:866032
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
You can’t perform that action at this time.