Skip to content

Instantly share code, notes, and snippets.

View sbellity's full-sized avatar

Stephane Bellity sbellity

View GitHub Profile
ROOT_PATH = File.expand_path("#{File.dirname(__FILE__)}/..") unless defined?(ROOT_PATH)
require "pp"
AppEnv = ENV["APP_ENV"] || "development"
DBConfig = YAML::load(open("config/database.yml"))[AppEnv]
def mysql_cmd cmd="mysql", *args
opts = {
:u => DBConfig["username"],
:h => DBConfig["host"],
:p => DBConfig["password"]
}.inject([]) { |c, o| o[1].nil? ? c : c << "-#{o[0]}#{o[1]}" }.join(" ")
$: << File.join(RAILS_ROOT, "lib/bm_master/gen-rb")
require "master"
require "thrift"
require "thrift/transport/http_client_transport"
transport = Thrift::HTTPClientTransport.new("http://10.101.0.97:3000/bm_service")
protocol = Thrift::BinaryProtocol.new(transport)
BmClient = BmMaster::Master::Client.new(protocol)
@sbellity
sbellity / objectid2x.rb
Created August 12, 2011 10:38
BSON ObjectId conversion to base X
require 'rubygems'
require 'bson'
require 'string'
DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(//)
def dec2x(number, base=16)
number = Integer(number);
@sbellity
sbellity / another_class.coffee
Created November 18, 2011 11:36
privated methods in coffeescript
class AnotherClass
constructor: ->
console.warn("YEAH !")
exports.AnotherClass = AnotherClass
@sbellity
sbellity / base_view_model.coffee
Created November 18, 2011 12:04
Base ViewModel Class for knockback ?
class BaseViewModel
constructor: (model, opts)->
@model = model
mapping = {}
@collections = {}
for k,v of model.attributes
if v instanceof Backbone.Collection
@[k] = ko.observableArray([])
vm_name = opts.viewModelName || k.singularize().camelize() + "ViewModel"
@sbellity
sbellity / observable_model.coffee
Created November 18, 2011 17:10
Knockit = Knockout + Backbone
class KnockItObservables
constructor: ->
@reset({})
make: (ref, attrs)->
return false unless ref && attrs
@_viewModels[ref] ?= ko.mapping.fromJS(attrs)
@_viewModels[ref].ref = ref
@_viewModels[ref]
@sbellity
sbellity / achieve_button.hbs
Created January 3, 2013 19:01
Hull Default Widgets templates
{{#if isAchieved}}
<button class="btn btn-success">Checked</button>
{{else}}
<button class="btn {{#unless canAchieve}}disabled{{/unless}}" data-hull-action="achieve_button.achieve">CheckIn</button>
{{/if}}
@sbellity
sbellity / main.js
Created April 12, 2013 09:57
Hull Profile Widget with data coming from Facebook
Hull.widget('profile', {
templates: ['profile'],
refreshEvents: ['model.hull.me.change'],
fields: [
{ name: 'name', type: 'text', placeholder: 'Name' },
{ name: 'email', type: 'text', placeholder: 'Email' }
],
@sbellity
sbellity / hull-init.rb
Last active December 19, 2015 17:29
hull-rails initializer
require 'handlebars_assets'
Hull.configure do |config|
# == Hull App Config
#
config.app_id = ENV["HULL_APP_ID"]
# == Hull App secret
# This is required to enable all server side secure stuff.