Skip to content

Instantly share code, notes, and snippets.

View pjambet's full-sized avatar

Pierre Jambet pjambet

View GitHub Profile
@pjambet
pjambet / gist:3702678
Created September 11, 2012 22:38
Why I don't like method missing
require 'benchmark'
class A
def m
@foo = 1
end
end
class B
def method_missing(meth, *args, &block)
@pjambet
pjambet / parameterize.js
Created September 12, 2012 22:30
Javascript implementation of Rails #parameterize method stolen from http://bit.ly/TUm5wK and quickly modified
var LATIN_MAP = {
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE', 'Ç':
'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I', 'Î': 'I',
'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O', 'Õ': 'O', 'Ö':
'O', 'Ő': 'O', 'Ø': 'O', 'Ù': 'U', 'Ú': 'U', 'Û': 'U', 'Ü': 'U', 'Ű': 'U',
'Ý': 'Y', 'Þ': 'TH', 'ß': 'ss', 'à':'a', 'á':'a', 'â': 'a', 'ã': 'a', 'ä':
'a', 'å': 'a', 'æ': 'ae', 'ç': 'c', 'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e',
'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i', 'ð': 'd', 'ñ': 'n', 'ò': 'o', 'ó':
'o', 'ô': 'o', 'õ': 'o', 'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u',
'û': 'u', 'ü': 'u', 'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y'
@pjambet
pjambet / sass_mixins.sass
Created September 16, 2012 18:00
My mixins
@mixin arrow_bottom_001($color: black, $width: 4px)
position: relative
&:after
content: ""
height: 0
width: 0
border-style: solid
border-width: $width
border-color: $color transparent transparent transparent
position: absolute
@pjambet
pjambet / fibo.js
Created September 19, 2012 20:53
Fibonacci with & without memoizer
var limit = 100000000
var fibonacci = function(n) {
if (typeof fibonacci.count === 'undefined') {
fibonacci.count = 0
}
fibonacci.count += 1
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2)
}
var start = new Date().getTime()
var garbageInput = form.children().last();
if(garbageInput.attr('id') == "javax.faces.ViewState") {
form[0].removeChild(garbageInput[0]);
}
# Create new comment
Comment.create( :author => "sacha", :message => "toto", :recipe => r)
# Ya plus simple
r.comments.create author: 'sacha', message: 'toto'
# Normalement ca devrait pas poser de problemes de mass assignment ca
def get_name_for_user user
user
end
module WillPaginate
module ActionView
def will_paginate(collection = nil, options = {})
options[:renderer] ||= FoundationLinkRenderer
super.try :html_safe
end
class FoundationLinkRenderer < LinkRenderer
protected
@pjambet
pjambet / test.py
Last active December 15, 2015 11:59
Why I hate PHP syntax
# user_id is an integer, follow is a hash wich values are all integers
# PHP
$userIds = array_unique(array_merge(array_values($follows), array($userId)));
# ruby
userIds = follows.keys.push(user_id).uniq
# python
userIds = set(follows.keys().append(user_id))
@pjambet
pjambet / fabfile.py
Created August 18, 2013 21:58 — forked from fiee/fabfile.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
fabfile for Django
------------------
see http://morethanseven.net/2009/07/27/fabric-django-git-apache-mod_wsgi-virtualenv-and-p/
modified for fabric 0.9/1.0 by Hraban (fiëé visuëlle)
several additions, corrections and customizations, too