Skip to content

Instantly share code, notes, and snippets.

View leucos's full-sized avatar
👽
Waiting for aliens

Michel Blanc leucos

👽
Waiting for aliens
  • devops.works
  • Lyon, France
View GitHub Profile
@leucos
leucos / gist:2147637
Created March 21, 2012 14:41
Ramaze user auth example (from Yorick Peterse)
## foo.rb [ruby]
require 'ramaze'
class User
def self.authenticate(credentials)
credentials if credentials['name'] == 'manveru' && credentials['pass'] == 'foo'
end
end
class Main < Ramaze::Controller
@leucos
leucos / README.markdown
Created March 28, 2012 15:35 — forked from deepakdargade/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
 # this function receives the typeahead object and the query string
@leucos
leucos / basic
Created March 29, 2012 07:27
Yield a block
def nyan(&block)
yield
end
nyan do
printf "Nyan"
end
@leucos
leucos / gist:2255639
Created March 30, 2012 21:51
Ruby croaks on composition
class Record < Sequel::Model
many_to_one :domain
plugin :validation_helpers, :composition
composition :serial,
:composer => proc { split(content) if type == 'SOA' },
:decomposer => (
proc do
....
@leucos
leucos / record.rb
Created March 31, 2012 15:21
An attempt with Sequel's composition plugin
#
# The purpose of the database is to hold nameserver zone records
#
# Unfortunately, the SOA type record contains several interesting space-separated
# "inner" fields we would like to access individually.
#
# The point is is to "autovivify" getters and
# setters for these "inner fields"
#
# I'll try to solve this using Sequel's composition plugin
require 'sequel'
DB = Sequel.sqlite
DB.run "CREATE TABLE records (name VARCHAR(255) PRIMARY KEY NOT NULL, type VARCHAR(5), content VARCHAR(255))"
DB.run "INSERT INTO records VALUES ('example.com', 'SOA', 'ns.example.com root.example.com 2012333335 28800 86400 3600000 86400')"
Soa = Struct.new(:ns, :email, :serial, :refresh,:retry, :expiry, :minimum)
class Record < Sequel::Model
many_to_one :domain
@leucos
leucos / domain.rb
Created April 1, 2012 17:22
Bypassing rendering
# Controller for Domains
#
class Domains < MainController
before_all do
# Context helps the default layout highlighting the good entry in the navbar
@context=:domains
end
render_custom :index do |action|
@leucos
leucos / testresult
Created April 19, 2012 17:18
Test failing on ansible/master
PYTHONPATH=./lib nosetests -v
test_one (TestPlayBook.TestPlaybook) ... FAIL
test_async (TestRunner.TestRunner) ... FAIL
test_command (TestRunner.TestRunner) ... ok
test_copy (TestRunner.TestRunner) ... ok
test_facter (TestRunner.TestRunner) ... FAIL
test_fetch (TestRunner.TestRunner) ... ok
test_git (TestRunner.TestRunner) ... ok
test_ping (TestRunner.TestRunner) ... ok
test_service (TestRunner.TestRunner) ... ok
@leucos
leucos / iptables.j2
Created April 20, 2012 16:37
Implementing composite firewall rules thanks to setup module with complex values
#
# Example trimmed for brevity.
#
#
# ######################################
# INPUT Dispatch
# ######################################
-A INPUT -p tcp -j TCP_IN
-A INPUT -p udp -j UDP_IN
-A INPUT -p icmp -j ICMP_IN
@leucos
leucos / helper_generate.rb
Created April 24, 2012 13:00
id-prégénération
require 'redis'
require 'resque'
module Ramaze
module Helper
module EntId
def EntId.generate
r = Redis.new
Resque.enqueue(Ramaze::Helper::EntIdGenerator) if r.scard('laclasse.entid').to_i <= 1
0