Skip to content

Instantly share code, notes, and snippets.

Jérémy Lecour jlecour

Block or report user

Report or block jlecour

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jlecour
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": {
View mysql-git-backup_alpha.sh
#!/bin/sh
set -e
if [ ! "`id -u`" -eq 0 ]; then
echo "Must be root !"
exit 0
fi
MYSQLUSER=root
@jlecour
jlecour / README.md
Last active Mar 2, 2016
Pretty prints the environment of execution of a program by its PID.
View README.md

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

# pidenv 1
HOME=/
TERM=linux
BOOT_IMAGE=/bzImage-3.14.32-xxxx-grs-ipv6-64
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
end
# concrete example :
def go_to(step:, options: [])
# when using Pry, the step variable is shadowed by the debugger `step` method
end
@jlecour
jlecour / scam.md
Last active Nov 27, 2015
Échange avec un arnaqueur
View scam.md

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.

Bonjour,

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
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|
yield(name)
}
else
final
end
end
View to_production.sh
#!/bin/sh
set -e
[ -n "$DEBUG" ] && set -x
CAP_BIN="bin/cap"
CAP_COMMAND="${CAP_BIN} production"
# git name-rev is fail
CURRENT=`git branch | grep '\*' | awk '{print $2}'`
@jlecour
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 http://www.airpair.com/js/javascript-framework-comparison

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
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)",
View README.md

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. [http://twitter.com/roidrage/status/464692600910651392]

let's say you have this html snippet :

<div>
A text that is too long to fit it's container
</div>
You can’t perform that action at this time.