Skip to content

Instantly share code, notes, and snippets.

View simonprev's full-sized avatar

Simon Prévost simonprev

View GitHub Profile
@simonprev
simonprev / gist:974566
Created May 16, 2011 14:49 — forked from ZenCocoon/gist:724366
Handling French date format in Ruby
## Try 1
# How could I get the following working nicely
Date.strptime("Ven 13 Mai. 2011, 16h00", "%a %d %b %Y, %Hh%M")
# I've tried to update Date::ABBR_DAYNAMES as follow
I18n.locale = :fr
Date::ABBR_DAYNAMES = I18n.t('date.abbr_day_names')
Date::ABBR_MONTHNAMES = I18n.t('date.abbr_month_names')
@simonprev
simonprev / gist:1462044
Created December 11, 2011 18:44
Horizontal centered menu
#horizontal-centered-menu {
float:left;
width:100%;
overflow:hidden;
position:relative;
ul {
clear:left;
float:left;
list-style:none;
position:relative;
@simonprev
simonprev / gist:3044224
Created July 3, 2012 23:55
Fix my Rdio
1. Open terminal.app
2. Paste this command: defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
(credit: https://twitter.com/defaultswrite/status/220164244954554368)
3. Open Rdio.app
4. Right click and show the inspector panel
5. In the console section, paste this line: $("head").append('<link href="https://s3.amazonaws.com/simon-dev/css/rdio.css" rel="stylesheet" type="text/css">')
# load the macvim version of terminal vim
if which mvim &> /dev/null; then
alias vim='mvim -v'
fi
alias v='vim'
@simonprev
simonprev / translatable.rb
Created March 5, 2013 19:55
R18n translations and go_i18n_field in 25 lines...
module Extensions
module Translatable
extend ActiveSupport::Concern
module ClassMethods
def translations(*fields)
fields.each do |field|
define_method field do read_translate(field) end
define_method "#{field}=" do |value| write_translate(field, value) end
@simonprev
simonprev / gist:5594433
Created May 16, 2013 19:37
String#upcase
'test_string'.upcase
#=> "TEST_STRING"
'test_string'.upcase!
#=> "TEST_STRING"
'TEST_STRING'.upcase
#=> "TEST_STRING"
'TEST_STRING'.upcase!
#=> nil
@simonprev
simonprev / phoenix-web-framework.md
Last active August 29, 2015 14:07
Phoenix - OpenCode XXII

Phoenix - Elixir Web framework

by

Simon Prévost, Développeur Web chez Mirego

(The slides were made for mdp)


@simonprev
simonprev / rate_limiting.ex
Last active August 29, 2015 14:07
Redis-backed rate limiting API
defmodule MyProject.Plugs.RateLimting do
import Plug.Conn
alias Exredis.Api, as: Redis
@ttl 60 # seconds
@limit 5 # requests count
@header_limit "x-rate-limit-limit"
@header_remaining "x-rate-limit-remaining"
@header_reset "x-rate-limit-reset"
@simonprev
simonprev / generate_placeholders.exs
Created January 22, 2019 13:23
Generate placeholder after Accent’s new feature
defmodule GeneratePlaceholders do
import Ecto.Query
alias Accent.Repo
@regex Langue.Formatter.Rails.placeholder_regex()
@document_id "85f15c8e-a5bb-4235-b04f-3ce04e672749"
def update_operations do
operations()