Skip to content

Instantly share code, notes, and snippets.

@enriclluelles
enriclluelles / memory.go
Created April 20, 2014 09:46
Consume 2.4gb of RAM firing blocked goroutines
package main
import (
"fmt"
"time"
)
var counter int = 0
var goroutines int = 500000
@enriclluelles
enriclluelles / vg-digitalocean.patch
Last active August 29, 2015 14:06
patch vagrant digitalocean so it sends user_data
From c89f4d9c261fd005258ac551f23dddc835ac719b Mon Sep 17 00:00:00 2001
From: Enric Lluelles <enric@lluell.es>
Date: Sat, 6 Sep 2014 02:06:02 +0200
Subject: [PATCH] Add user data as a provider param
---
lib/vagrant-digitalocean/actions/create.rb | 3 ++-
lib/vagrant-digitalocean/config.rb | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
@enriclluelles
enriclluelles / ext.vim
Last active August 29, 2015 14:11 — forked from sjl/ext.vim
" run command
" no stdin
" output displayed in "Press enter to continue" style
" current buffer untouched
:!uptime
" run command
" pipe range of text to command on stdin
" output replaces the range in the current buffer
:RANGE!grep foo
@enriclluelles
enriclluelles / gist:12927db9d03bee833520
Created December 18, 2014 17:59
Efficient way of getting a HMACSHA256 payload out of a string and a secret in clojure
(defn hmacSHA256
(memoize (fn [payload secret]
(let [mac (Mac/getInstance "HMACSHA256")
secretKey (SecretKeySpec. (.getBytes secret) (.getAlgorithm mac))
byteResult (-> (doto mac
(.init secretKey))
(.doFinal (.getBytes payload)))
stringResult (->> byteResult
(map #(format "%x" %))
(apply str))]
@enriclluelles
enriclluelles / happy.clj
Last active August 29, 2015 14:15
Happy numbers kata
(require ['clojure.set])
(def happy-numbers (set [1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]))
(def not-happy-numbers (clojure.set/difference (set (range 1 100)) happy-numbers))
(defn decompose-in-digits [n]
(map #(Character/digit % 10) (str n)))
(def square #(*' % %))
(defn- happy? [n visited]
(ns diamond.core
(:require [clojure.string :refer [join]]))
(defn char-range [start end]
(map char (range (int start) (inc (int end)))))
(defn steps
[c]
(map str (char-range \A c)))
class Lesson < ActiveRecord::Base
belongs_to :period
validates_presence_of :period_id
end
class Period < ActiveRecord::Base
has_many :lessons, :dependent=>:delete_all
validates_associated :lessons
end
MiniTest::Unit::IntegrationTestCase.class_variable_get(:@@inheritors).each do |klass|
klass.module_eval do
alias_method :setup_with_no_hook, :setup
def setup
Capybara.current_driver = :selenium_chrome
setup_with_no_hook
end
alias_method :teardown_with_no_hook, :teardown
def teardown
@enriclluelles
enriclluelles / sass.rb
Created November 11, 2011 13:51
Stop Sass::Plugin from double compiling stuff
if Rails.configuration.try(:sass)
Rails.application.config.middleware.delete(Sass::Plugin::Rack)
Rails.configuration.sass.tap do |config|
config.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
config.preferred_syntax = :sass
end
end
Views = {
render: function (name, locals) {
var tmpl = $("[name=" + name + "]").html();
var locals = locals || {};
return require("jade.js").compile(tmpl)(locals);
},
replace: function (sel, name, locals) {
return sel.html(this.render(name, locals));
}