Skip to content

Instantly share code, notes, and snippets.

View jlecour's full-sized avatar

Jérémy Lecour jlecour

View GitHub Profile
@jlecour
jlecour / fs-to-json.py
Last active July 25, 2023 15:01
A script to transform a filesystem tree into a JSON structure, a little like an inverse procfs/sysfs.
#!/bin/env python
import sys
import os
import json
def clean_lines(lines):
clean_lines=[]
# TODO: a map/reduce or a comprehension might be better
for line in lines:
@jlecour
jlecour / mapping.json
Last active October 31, 2016 11:28
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.
{
"mappings": {
"tweet": {
"properties": {
"created_at": {
"format": "YYYY-MM-dd HH:mm:ss Z",
"type": "date"
},
"entities": {
"properties": {
#!/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 March 2, 2016 09:28
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
HOME=/
TERM=linux
BOOT_IMAGE=/bzImage-3.14.32-xxxx-grs-ipv6-64
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 November 27, 2015 10:43
É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.

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 October 14, 2015 08:19
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 ?
def prelude
if block_given?
final { |name|
yield(name)
}
else
final
end
end
#!/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 August 29, 2015 14:06
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.

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 August 29, 2015 14:02
A very naive attempt to prevent script injection in Elasticsearch requests. `distance_script_field` is an helper used to help build a complete request.
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)",