Skip to content

Instantly share code, notes, and snippets.

View budu's full-sized avatar
😀

Nicolas Buduroi budu

😀
View GitHub Profile
SimpleForm::FormBuilder.class_eval do
def input_with_bs_cols(attribute_name, options = {}, &block)
bs_cols_classes = parse_bs_cols_option(options)
if bs_cols_classes
wrapper_html_options = (options[:wrapper_html] || {})
.merge_html_attributes(class: bs_cols_classes.join(' '))
options[:wrapper_html] = wrapper_html_options
Hash.class_eval do
def recursive_map_values(&block)
reduce({}) do |m, (k, v)|
m[k] = v.is_a?(Hash) ? v.recursive_map_values(&block) : block.call(self, k, v)
m
end
end
end
@budu
budu / bacon-proto.rb
Created November 14, 2013 02:41
Prototype of a new DSL to consume json API
module Bacon
class Resource
def initialize(name, parent, options = {})
@name = name
@parent = parent
@options = options
@result = options[:result] || []
end
# app/admin/account.rb for toplevel configuration options
ActiveAdmin.register Account do
config.batch_actions = false
end
# app/admin/account/form.rb
ActiveAdmin.register Account do
form do |f|
@budu
budu / hash.rb
Last active December 11, 2015 03:49
class Hash
def as_object
HashObject.new self
end
end
#> o = { foo: (->(this) { puts this.bar }), bar: 'hello') }.as_object
#> o.foo
# => hello
require 'spork'
require 'database_cleaner'
ENV["RAILS_ENV"] ||= 'test'
def configure_rspec
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
@budu
budu / Gemfile
Created May 25, 2012 19:37
Basic Stasis/Kramdown powered blog
source 'http://rubygems.org/'
gem 'coffee-script'
gem 'compass'
gem 'guard'
gem 'guard-shell'
gem 'haml'
gem 'rb-inotify'
gem 'kramdown'
gem 'nokogiri'
@budu
budu / state_macros.clj
Created April 17, 2012 02:43
Poor's man state monad!
(defmacro << [k-or-ks f]
`(fn [state#]
(update-in state#
~(if (vector? k-or-ks)
k-or-ks
(vector k-or-ks))
~f)))
(defn >>* [state form]
(condp = (first form)
@budu
budu / xkcd287.clj
Created April 17, 2012 02:24
Logic puzzle: XKCD #287 solution in Clojure core.logic
(use 'clojure.core.logic)
(def rvar? (comp not lvar?))
(defmacro arithm [r x y op po]
`(fn [a#]
(let [r# (walk a# ~r)
x# (walk a# ~x)
y# (walk a# ~y)]
(cond
@budu
budu / ComUtils.cs
Created April 12, 2012 19:40
Utility class to extract properties dynamically from a COM object. This provide a method that extract all of a given object properties (even those taking parameters) and generate a nice set of nested dictionnaries.
public static class ComUtils
{
public static object Get(object obj, string key, object[] args = null)
{
return obj.GetType().InvokeMember(
key,
System.Reflection.BindingFlags.GetProperty,
null,
obj,
args);