Skip to content

Instantly share code, notes, and snippets.

part time available for intersting projects

mfo mfo

part time available for intersting projects
View GitHub Profile
mfo / streaming_render_test.rb
Last active Aug 23, 2017
StreamingTemplateRenderer maybe cleaner
View streaming_render_test.rb
# frozen_string_literal: true
require "fiber"
module ActionView
# == TODO
# * Support streaming from child templates, partials and so on.
# * Rack::Cache needs to support streaming bodies
class StreamingTemplateRenderer < TemplateRenderer #:nodoc:
# Ruby fibers does not support Thread.current[:locals]
View sample.rb
EventMachine::HttpRequest.use EventMachine::Middleware::JSONResponse
# prepare request
con ='', {
connect_timeout: 0,
inactivity_timeout: 0,
keepalive: true
# plug oauth
con.use EventMachine::Middleware::OAuth({...keys..})
# setup tracking
mfo /
Last active Apr 30, 2016
wip: extract all uniq font awesome
grep -r "fa-" \
--include=\*.{rb,haml,jst,js} \
--exclude=\*xregexp\* \
--exclude-dir={public,.//app/assets/javascripts/i18n,.//app/assets/javascripts/i18n/web} \
./ \
> icons.txt
ruby -e '"./icons.txt").scan(/(fa(?:-\w+)+)/).flatten.uniq'
mfo /
Last active Apr 30, 2016
zopfli on snap-ci
# make zopfli
pushd .
git clone zopfli-build && cd zopfli-build && make
export PATH="$PATH:$(pwd)"
# after assets precompile, zopfli all of them [nproc/sysctl -n hw.ncpu for compat btw centos & macox]
find public/assets | grep -E '.*\.(css|js)$' | xargs -P $(if [ $(which nproc) ]; then nproc; else sysctl -n hw.ncpu; fi;) zopfli
mfo / looking_for_ideas.rb
Created Apr 5, 2013
Looking for an idea for a graceful way to DRY repetition regarding the error rescuing...
View looking_for_ideas.rb
class Api::CollectionsController < ApplicationController
def update
@collection = Collection.where(pname: params[:id], event_id:
@collection.assign_to(@event, params[:collection])
@status =! ? "ok" : "ko"
render status: 200
rescue Exception => e
@status = "ArgumentError"
@error = @collection.errors.keys
mfo / coolline.rb
Last active Dec 14, 2015
When using pry-cooline (, enable to suspend the REPL by hitting C-z. Use `fg` to bring it back to the front
View coolline.rb
# $HOME/.config/coolline/coolline.rb, see
Coolline.bind "\C-z" do |cool|
`kill -s TSTP #{}`
mfo /
Last active Dec 11, 2015
Example of heroku-forward with SSL support for your development environment

create SSL certificates for thin / heroku-forward

# create an SSL folder for your environment.
mkdir -p ~/.ssl/development/
cd ~/.ssl/development/

# create private key / certificate for your app 
# /!\ remember to define the expected common name for you development hostname [if your using localhost, use localhost. If you are using a custom domain, use it]
openssl genrsa -out my_app_key.pem 1024 
mfo / embedded_javascript.html
Created Aug 18, 2012
example of embedded JS
View embedded_javascript.html
<div class="sharypic_widget" data-sharypic-uid='4sacwgos3b8s8w46' style='height: 240px; width: 320px;'/>
<script language='javascript'>
(function(){var a=document.createElement("script");a.type="text/javascript";a.async=true;a.src="";var b=document.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)})()
mfo /
Created Aug 18, 2012
Async GA trackr for 3rd party Analytics
# it's an IIFE (Immediately-Invoked Function Expression) expeting jQuery as argument
(($) ->
# by default, i'm expecting window.sharypic declared as a namespace to declare a new class
class window.sharypic.WidgetTrackr
# should be called one time, and inserting / creating [or not], a new GA trackr
constructor: -> @insert()
# insert the google tracking code inside the webpage
insert: ->
window._gaq = window._gaq || [];
mfo /
Created Apr 28, 2012
mongo utilities
# dropdb from console
$> mongo --eval "db.dropDatabase();" databasename
# restore a db from a backup
$> mongorestore -vvv sharypic_development
# run mongo console
$> mongo
# a few usefull command on mongo cli