Skip to content

Instantly share code, notes, and snippets.


Jérémy Lecour jlecour

View GitHub Profile
jlecour / mapping.json
Last active Oct 31, 2016
A (not optimized at all) Ruby script to import tweets from a Twitter Archive to an Elasticsearch index. The mapping can be PUT to the index beforehand, to optimize indexing.
View mapping.json
"mappings": {
"tweet": {
"properties": {
"created_at": {
"format": "YYYY-MM-dd HH:mm:ss Z",
"type": "date"
"entities": {
"properties": {
set -e
if [ ! "`id -u`" -eq 0 ]; then
echo "Must be root !"
exit 0
jlecour /
Last active Mar 2, 2016
Pretty prints the environment of execution of a program by its PID.

Give pidenv the PID of a running program and it will print (with correct line breaks) its environment.

# pidenv 1
View arguments.rb
def my_method(arg1:, arg2:)
# how to get the keys/values or arguments, when they also exist as a method?
# instance_variable_get("…"), and instance_variable_names are for instance variables
# concrete example :
def go_to(step:, options: [])
# when using Pry, the step variable is shadowed by the debugger `step` method
jlecour /
Last active Nov 27, 2015
Échange avec un arnaqueur

L'arnaqueur, se faisant passer pour Jean-Bernard F., m'écrit sur l'adresse d'assistance du site pour lequel je travaille.

Le personne (son addresse est en signature de chaque mail de l'arnaqueur) existe vraiment, c'est donc probablement une usurpation d'identité. Je l'ai prévenu par d'autres moyens.


J'aimerais te parler sérieusement es tu disponible par mail. Je te demande de garder surtout la confidentialité de mon courriel n'en parle à personne je t'en prie.

Merci d'avance.

jlecour / pass_blocks_around.rb
Last active Oct 14, 2015
Is there a better way to have a first method (`prelude` here) accept an optional block, pass it to another method (`final` here) and have it yielded in the end, without having to yield also in the first method ?
View pass_blocks_around.rb
def prelude
if block_given?
final { |name|
set -e
[ -n "$DEBUG" ] && set -x
CAP_COMMAND="${CAP_BIN} production"
# git name-rev is fail
CURRENT=`git branch | grep '\*' | awk '{print $2}'`
jlecour / gist:e1cc391f40f13aa8c9c6
Last active Aug 29, 2015
I want to build a very simple web app to use (mostly offline) on my iPhone. It will be a simple form to input data (timestamp, key, value), store them in a local storage and occasionally push them to a remote API. I've asked for advice on the building blocks. Here are the answers I've received so far.
View gist:e1cc391f40f13aa8c9c6

chibani: @jlecour il te faut quoi ? Un champ date, 2 champs number et stocker en bdd locale ? Ensuite un bouton pour demander le push vers ton ES ?

sgruhier: @jlecour This are 2 difference things. You can do offline webpage in any technology you want.

duckmole: @jlecour

franckverrot: @jlecour depends on the effort you wanna put into this IMHO. I worked a lot with both and I personally prefer Ember.

gcouprie: @jlecour React. Ca te simplifie la gestion de la donnée

jlecour / better_protected.rb
Last active Aug 29, 2015
A very naive attempt to prevent script injection in Elasticsearch requests. `distance_script_field` is an helper used to help build a complete request.
View better_protected.rb
def distance_script_field(name: "distance", field: "lat_lng", lat:, lng:)
valid_pattern = /\A[\w]+\Z/
valid_pattern.match(name) or fail(ArgumentError, "Invalid value for name: #{name.inspect}")
valid_pattern.match(field) or fail(ArgumentError, "Invalid value for field: #{field.inspect}")
Float(lat) rescue raise(ArgumentError, "Invalid value for lat: #{lat.inspect}")
Float(lng) rescue raise(ArgumentError, "Invalid value for lng: #{lng.inspect}")
name => {
script: "doc['#{field}'].arcDistanceInKm(lat,lon)",

roidrage: Is there a CSS trick that allows me to phase out text that overflows a box? Like a shadow over the last couple of chars. []

let's say you have this html snippet :

A text that is too long to fit it's container