Skip to content

Instantly share code, notes, and snippets.

View rpechayr's full-sized avatar

Romain Péchayre rpechayr

View GitHub Profile
@rpechayr
rpechayr / asdf-plugins.md
Created May 4, 2021 15:43
Asdf ruby python node.js plugins
@rpechayr
rpechayr / count.rb
Created November 30, 2016 08:26
How fast is a computer to count from 0 to 100
beginning = Time.now
1.upto(100).each do |i|
puts i
end
puts "Elapsed #{Time.now - beginning}"
@rpechayr
rpechayr / exp.erl
Created April 12, 2016 08:36
Erlang evaluation exercise
-module(exp).
-export([parse_expression/1, evaluate_expression/1]).
parse_expression(Exp) ->
parse_acc(Exp, {unknown, unknown, unknown}).
convert_operator(Char) ->
case Char of
$- -> minus;
$+ -> plus;
@rpechayr
rpechayr / .gitconfig
Last active December 4, 2015 09:27
My git aliases (gitconfig extract)
[alias]
co = checkout
ci = commit
br = branch
st = status
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
m = checkout master
fo = fetch origin
mom = merge origin master
sweep = !git branch --merged master | grep -v 'master$' | xargs git branch -d\
@rpechayr
rpechayr / fast-mongo.rb
Last active October 12, 2015 14:22
Different cases with down hosts
require 'mongo'
#Here I don't have any mongod listening on port 29017
client = Mongo::Client.new([ "127.0.0.1:29017", '127.0.0.1:27017' ], :database => 'test')
result = client[:artists].insert_one({ name: 'FKA Twigs' })
@rpechayr
rpechayr / upgrade.md
Last active August 26, 2016 09:53
Upgrading to Mongoid 5.x

Upgrade to Mongoid 5.x

Mongoid 5 is a major upgrade to Mongoid for several reasons :

Here is a non comprehensive list of things to chexk or upgrade.

  • Mongoid.yml. The driver changes, so the options you pass to mongoid.yml also do. You should generate a brand new one and find the equivalent options you were using. The sessions entry has been replaced by the clients entry.
  • Aggregation. User.collection.aggregate now requires an array as argument, not a variable number of hashes
  • Moped:: classes like Errors or BSON don't exist anymore.
@rpechayr
rpechayr / regex.rb
Created September 4, 2015 09:39
Huge regex match time
bod = "![image](https://cloud.githubusercontent.com/assets/8692675/8456774/3716d8f6-20d6-11e5-8b20-e0085491c2b6.png)\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n--- \n**Pivotal Tracker** - [#100934594](https://www.pivotaltracker.com/story/show/100765594)\n*Estimation*: **2.0 points**\n*ETA*: **14th August 2015**\n\n--- \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
reg = /^--- (.|\n)*--- /m
hello = "hi"
bod.gsub(reg, hello)
@rpechayr
rpechayr / some_view.html.erb
Created August 21, 2015 12:44
include a javascript file in an erb view
<%= javascript_include_tag "react/application" %>
@rpechayr
rpechayr / application.rb
Created August 21, 2015 12:41
Add a new js file for assets pipeline
config.assets.precompile += ['react/application.js']
@rpechayr
rpechayr / application.js
Created August 21, 2015 12:40
Load bundle.js from assets pipeline
//= require ./bundle.js