Skip to content

Instantly share code, notes, and snippets.

View olivoil's full-sized avatar

Olivier Melcher olivoil

View GitHub Profile
@olivoil
olivoil / ngrams-and-tire.rb
Created June 5, 2012 19:49 — forked from karmi/ngrams-and-tire.rb
An example of using ngram analysis in ElasticSearch with the Tire rubygem
# An example of using ngram analysis in ElasticSearch with the Tire rubygem
# ==========================================================================
# The original, raw example: https://gist.github.com/988923
require 'rubygems'
require 'tire'
require 'yajl/json_gem'
class URL
def initialize(attributes={})
@olivoil
olivoil / Coffeescript ctags
Created June 10, 2012 04:41 — forked from bjornharrtell/Coffeescript ctags
ctags definitions for coffeescript. Detects classes, static/class methods, plain functions and variables.
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z]+\.)*([A-Za-z]+)( extends [A-Za-z.]+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z.]+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*@([A-Za-z.]+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*([A-Za-z.]+):[^->\n]*$/\1/f,field/
--regex-coffee=/(constructor: ).@([A-Za-z.]+)/\2/f,field/
@olivoil
olivoil / hstore_accessor.rb
Created June 16, 2012 01:48 — forked from inopinatus/hstore_accessor.rb
hstore accessor class method for AR
# put this file in lib/ and include it from an initializer
module HstoreAccessor
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def hstore_accessor(hstore_attribute, *keys)
serialize hstore_attribute, ActiveRecord::Coders::Hstore
@olivoil
olivoil / phantom.coffee
Created June 24, 2012 15:05 — forked from BinaryMuse/phantom.coffee
Take screenshots with Phantom.js from Node.js
#!/usr/bin/env coffee
# Call the program with: coffee phantom.coffee http://url.to/screengrab
phantom = require 'phantom' # npm install phantom
child_process = require 'child_process'
url = process.argv[2]
createScreenshot = (page, filename) ->
if Rails.env.production?
Braintree::Configuration.environment = Rails.env.staging? ? :sandbox : :production
Braintree::Configuration.merchant_id = ENV["braintree_merchant_id"]
Braintree::Configuration.public_key = ENV["braintree_public_key"]
Braintree::Configuration.private_key = ENV["braintree_private_key"]
else
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.merchant_id = "<super secret>"
Braintree::Configuration.public_key = "<super secret>"
Braintree::Configuration.private_key = "<super secret>"
@olivoil
olivoil / example.rb
Created October 25, 2012 20:48 — forked from joakimk/example.rb
A simple form object built on top of virtus.
class Filter
include FormObject
# Proc because Date.yesterday changes every day :)
attribute :from, Date, default: Proc.new { Date.yesterday }
attribute :to, Date, default: Proc.new { 1.month.from_now - 1.day }
end
# in controller
@filter = Filter.new(params[:filter])
<html>
<head>
<script type="text/javascript" charset="utf-8">
var FB = function(){
//defaults and accessors
var initialized = false,
loggedIn = null,
shouldSucceed = true,
uid = '12345';
@olivoil
olivoil / Custom.css
Last active December 15, 2015 14:59 — forked from nixpulvis/Custom.css
body { -webkit-transform: rotate(10deg); }
body { -webkit-animation: blur 30s infinite; }
img { -webkit-transform: rotate(180deg); }
body, p, body p, body div p { font-family: 'Comic Sans MS', cursive !important; }
p:before { content: "YOLO "; }
p:nth-child(2) { display:none !important; }
#-webkit-web-inspector { -webkit-transform:rotate(180deg); }
#-webkit-web-inspector .toolbar-item.close-left { display:none !important; }
html { -webkit-animation: rainbow 8s infinite; }
@-webkit-keyframes blur {
// http://www.w3.org/TR/dom/
// http://updates.html5rocks.com/2012/02/Detect-DOM-changes-with-Mutation-Observers
// https://developer.mozilla.org/en-US/docs/DOM/MutationObserver
var MutationObserver = (function () {
var prefixes = ['WebKit', 'Moz', 'O', 'Ms', '']
for(var i=0; i < prefixes.length; i++) {
if(prefixes[i] + 'MutationObserver' in window) {
return window[prefixes[i] + 'MutationObserver'];
}
}
@olivoil
olivoil / uustats.js
Created October 18, 2013 02:01 — forked from akdubya/uustats.js
(function(uustats){
uustats.sdev = function(series) {
return Math.sqrt(uustats.variance(series));
};
uustats.variance = function(series) {
var t = 0, squares = 0, len = series.length;
for (var i=0; i<len; i++) {