Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
#^syntax detection
site 'http://community.opscode.com/api/v1'
cookbook 'ntp'
cookbook 'timezone', '0.0.1'
cookbook "monit",
:github => "apsoto/monit"
@lastcanal
lastcanal / luerl_table_with_erlang_fun.erl
Last active September 12, 2016 23:06
Setting Erlang functions as values on a Luerl tables
%% Initialize the luerl state
Lua0 = luerl:init(),
%% Create a new empty table
{HttpTable, Lua1} = luerl_emul:alloc_table(Lua0),
%% Set the empty table to the global key `http`
Lua2 = luerl_emul:set_global_key(<<"http">>, HttpTable, Lua1),
%% You can also set up the global table from Lua
@lastcanal
lastcanal / padrino_locales_ar_to_ohm.rb
Created April 6, 2013 16:35
Adds Ohm model errors to padrino admin locales.
require 'yaml'
$mapping = {
format: :invalid,
not_present: :blank,
not_numeric: :not_a_number,
not_url: :invalid,
not_email: :invalid,
not_valid: :inclusion,
not_in_range: :inclusion,
@lastcanal
lastcanal / en.yml
Created March 31, 2013 16:15
Padrino Admin ORM locale with Ohm
en:
activemodel: &activemodel
errors:
messages:
inclusion: "is not included in the list"
exclusion: "is reserved"
invalid: "is invalid"
confirmation: "doesn't match confirmation"
accepted: "must be accepted"
empty: "can't be empty"
%% File : hello_table.erl
%% Purpose : Demonstration of luerl:table.
%% Use $ erlc hello_table.erl && erl -pa ../../ebin -s hello_table run -s init stop -noshell
-module(hello_table).
-export([run/0]).
run() ->
LuaScript = <<"hello_table = { hello=\"world\" }; return table;">>,
{_Val, Lua0} = luerl:do(LuaScript),
1> luerl:load(<<"table = { hello=\"world\" }; return table">>).
{ok,{code,[{fdef,1,0,1,
[{push_lit,<<"hello">>},
{push_lit,<<"world">>},
{load_lit,[]},
{build_tab,1,0.0},
{store_gvar,<<"table">>},
multiple,
{return,1}]}],
{cst}}}
table: 0x7fe851c06b50
hello
table: 0x7fe851c06b50
hello hello2
@lastcanal
lastcanal / luerl-bench-1000.txt
Created February 21, 2013 05:57
Luerl benchmark at 1000 iterations on a macbook air
➜ benchmark git:(benchmark) ✗ make
erlc -I ../../src benchmarks.erl
erl -pa ../../ebin -s benchmarks run -s init stop -noshell
suites/accum.lua ms
ipairs.................. 1617.325
next.................... 2649.867
numeric_for............. 1591.269
numeric_while........... 2686.428
pairs................... 1624.004
@lastcanal
lastcanal / luerl_table_function.erl
Last active December 13, 2015 22:59
Proposed example interface for luerl tables
-module(luerl_table_function).
-export(run/0).
%% Get table or table key
%% luerl:table(Fpath, Lua) -> {ok, Value}
%% Set table or table key
%% luerl:table(Fpath, Value, Lua) -> {ok, Lua}
run() ->
Lua0 = luerl:init(),
require 'fog/vcloud'
# connect to cloud
connection = Vcloud::Compute.new(
:vcloud_host => 'vcloud.moc',
:vcloud_username => 'username',
:vcloud_password => 'password'
)
# virtual image template