Skip to content

Instantly share code, notes, and snippets.

View jlecour's full-sized avatar

Jérémy Lecour jlecour

View GitHub Profile

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 / 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)
@jlecour
jlecour / post_to_slack.rb
Last active May 22, 2022 17:43
How to post alerts from Monit to Slack
# encoding: UTF-8
require 'optparse'
require 'net/http'
require 'json'
def parse_options(argv)
opts = {}
@parser = OptionParser.new do |o|

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 / monit_sidekiq
Created March 10, 2014 09:17
Monit configuration for 2 Sidekiq processes, with Rbenv.
check process sidekiq_01
with pidfile /path/to/app/current/tmp/pids/sidekiq.pid
start program = "/bin/sh -c 'cd /path/to/app/current; PATH=bin:/path/to/rbenv/shims:/path/to/rbenv/bin:$PATH nohup bundle exec sidekiq -e production -i 0 -P tmp/pids/sidekiq.pid >> log/sidekiq.log 2>&1 &'" as uid app_user and gid app_group with timeout 90 seconds
stop program = "/bin/sh -c 'cd /path/to/app/current; PATH=bin:/path/to/rbenv/shims:/path/to/rbenv/bin:$PATH bundle exec sidekiqctl stop tmp/pids/sidekiq.pid'" as uid app_user and gid app_group with timeout 90 seconds
if totalmem is greater than 500 MB for 2 cycles then restart # eating up memory?
group sidekiq
check process sidekiq_02
with pidfile /path/to/app/current/tmp/pids/sidekiq.pid-1
start program = "/bin/sh -c 'cd /path/to/app/current; PATH=bin:/path/to/rbenv/shims:/path/to/rbenv/bin:$PATH nohup bundle exec sidekiq -e production -i 1 -P tmp/pids/sidekiq.pid-1 >> log/sidekiq.log 2>&1 &'" as uid app_user and gid app_group with timeout 90 seconds
@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
@jlecour
jlecour / clear_projects_logs.sh
Created December 6, 2013 10:21
A small shell script to remove useless logs (other environments than development) and truncate all other log files
#!/bin/sh
for file in `ls ~/Projects/*/log/*_{production,staging,sandbox}.log`; do
rm $file
echo "remove $file"
done
for file in `ls ~/Projects/*/log/*.log`; do
echo '' > $file
echo "truncated $file"
@jlecour
jlecour / _no_commit_on_master
Created October 31, 2013 10:19
Git Hooks (must be executable)
#!/bin/sh
if [[ `git symbolic-ref HEAD` == "refs/heads/master" ]]
then
echo "You cannot commit in master!"
exit 1
fi
>>> Installing rubinius 2.1.0 into /opt/rubies/rubinius-2.1.0 ...
>>> Installing bundler ...
Successfully installed bundler-1.3.5
Parsing documentation for bundler-1.3.5
1 gem installed
>>> Downloading http://releases.rubini.us/rubinius-2.1.0.tar.bz2 into /usr/local/src ...
>>> Verifying rubinius-2.1.0.tar.bz2 ...
>>> Extracting rubinius-2.1.0.tar.bz2 ...
>>> Bundling rubinius 2.1.0 ...
Using rake (10.1.0)

It's an implementation of a previously submitted problem.

The models are simple Virtus objects. We can use them as plain Ruby objects.

The mapper is like a factory or a builder. It is xecuted with the data source (JSON here) and returns the models tree.

The JSON and XML parsers are just boilerplate code.