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 / update_elasticsearch.sh
Created March 7, 2014 19:42
Update Elasticsearch on a Debian system
cd /tmp
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.1.deb
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.1.deb.sha1.txt
grep -f elasticsearch-1.0.1.deb.sha1.txt <(sha1sum elasticsearch-1.0.1.deb) && echo "checksum OK"
mount -o remount,rw /usr
service elasticsearch stop
dpkg -i elasticsearch-1.0.1.deb
cd /usr/share/elasticsearch/
bin/plugin -remove mobz/elasticsearch-head

Keybase proof

I hereby claim:

  • I am jlecour on github.
  • I am jlecour (https://keybase.io/jlecour) on keybase.
  • I have a public key whose fingerprint is 6354 41B7 AE3D AF2F B458 B6EB F2D3 E9D7 13FF DD52

To claim this, I am signing this object:

@jlecour
jlecour / find_each.rb
Created April 7, 2014 09:44
This is a snippet of code that I've ben using in a custom repository implementation, pretty similar to `persistence` from @karmi : https://github.com/elasticsearch/elasticsearch-rails/blob/persistence/elasticsearch-persistence/README.md
def find_each(options = {}, &block)
search_options = {}
search_options[:index] = options.fetch(:index) { default_index(options) }
search_options[:body] = options.fetch(:body) {
{ query: { match_all: {} } }
}
search_options[:scroll] = options.fetch(:scroll) { "5m" }
search_options[:search_type] = "scan"
if options.key?(:_source)

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>
@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)",
@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

#!/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}'`
def bash_format(formats, text)
res = "\e[0"
colors = { :red =>";31", :yellow => ";33", :green => ";32" }
styles = { :bold => ";1", :underline => ";4" }
if formats.is_a?(Array) || formats.is_a?(Hash)
colors.each { |k,v| res += v if formats.include?(k) }
styles.each { |k,v| res += v if formats.include?(k) }
elsif formats.is_a?(Symbol)
colors.each { |k,v| res += v if formats == k }
styles.each { |k,v| res += v if formats == k }
#!/usr/bin/env ruby
#
# A hook script to verify that only syntactically valid ruby code is commited.
# Called by git-commit with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# Put this code into a file called "pre-commit" inside your .git/hooks
# directory, and make sure it is executable ("chmod +x .git/hooks/pre-commit")
#
J'ai un dégoût personnel pour les conférences le week-end. Pour moi, une conférence le week-end garanti que je vais "bosser" 12 jours d'affilée.
J'ai bien conscience que cette opinion n'est pas universelle.
Certaines personnes ont des difficultés pour "décrocher" pour aller à des conférences. Ces situations ont bien l'air d'une mécompréhension des responsabilités d'un développeur logiciel. Une partie de votre boulot (de développeur logiciel) est de rester à jour technologiquement. Ça signifie passer du temps de recherche durant votre journée.
(à peu près piqué directement à Ward sur le [déficit technique](http://c2.com/cgi/wiki?WardExplainsDebtMetaphor))
Si vous passez toute votre journée à coder, sans jamais regarder du coté des nouvelles choses, vous accroissez votre déficit technique. À court terme (disons la dernière semaine avant une release), ça a du sens de prendre un peu de déficit. Par contre, à long terme, sans un minimum d'investissement, l'intérêt (où l'intérêt est égal à la distance entre vos