Skip to content

Instantly share code, notes, and snippets.

View oscherler's full-sized avatar

Olivier Scherler oscherler

View GitHub Profile
@oscherler
oscherler / mount.py
Created April 26, 2011 18:34
Trailing slash problem with Flask application dispatching
from werkzeug.wsgi import DispatcherMiddleware
from flask import Flask
from sub_app import app as subapp
app = Flask( __name__ )
# dispatch by path
app.wsgi_app = DispatcherMiddleware( app.wsgi_app, {
'/sub': subapp.wsgi_app
@oscherler
oscherler / gist:3193052
Created July 28, 2012 12:12
Hacks to correct annoying Facebook bugs
// facebook init
window.fbAsyncInit = function() {
FB.init( {
appId : app_id, // App ID
channelURL : channel_url, // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
@oscherler
oscherler / ReadMe.md
Created August 17, 2012 18:34
Quick and dirty minified web service

Very quick and dirty modification of Ben Pickles' minify, moving the actual minification to a web service in case you already have a minification workflow in place but don't want to install java on your development virtual machine.

You need Ruby, gems sinatra and closure-compiler (and thus Java) on the machine that hosts the web service.

Start the web service with

ruby app.rb
<table>
<thead><tr>
<th><strong>PHPStorm</strong></th>
<th><strong>NetBeans</strong></th>
</tr></thead>
<tbody>
<tr>
<td colspan="2">Can debug PHP with XDebug (#1 feature for me)</td>
</tr>
<tr>
@oscherler
oscherler / composer.json
Created May 19, 2014 11:53
Sample code trying to show whether Zend Barcode depends on Zend Validator and/or Zend Service Manager.
{
"require": {
"zendframework/zend-barcode": "@stable"
}
}

Installing RabbitMQ and the PHP PECL extension on Ubuntu 14.04 LTS

RabbitMQ apt repository

sudo add-apt-repository 'deb http://www.rabbitmq.com/debian/ testing main'
curl http://www.rabbitmq.com/rabbitmq-signing-key-public.asc | sudo apt-key add -
sudo apt-get update

RabbitMQ server and management plug-in

@oscherler
oscherler / pieces.erl
Created February 22, 2017 09:06
Recursion exercise in Erlang.
-module( pieces ).
% I export fac and binomial so I can play in the shell.
-export( [ fac/1, binomial/2, pieces/2, test2d/0, test3d/0 ] ).
% Hopefully tail-recursive factorial. I’ve been reading ahead ;)
fac( N ) ->
fac( 1, N ).
fac( Acc, 0 ) ->
Acc;
@oscherler
oscherler / adjacent.S
Created February 23, 2017 20:22
Different versions of fib in Erlang
{function, fibP, 1, 2}.
{label,1}.
{line,[{location,"adjacent.erl",4}]}.
{func_info,{atom,adjacent},{atom,fibP},1}.
{label,2}.
{test,is_eq_exact,{f,3},[{x,0},{integer,0}]}.
{move,{literal,{0,1}},{x,0}}.
return.
{label,3}.
{allocate,0,1}.

bits.erl

Function that takes a positive integer N and returns the sum of the bits in the binary representation. For example bits(7) is 3 and bits(8) is 1. Direct and tail-recurive versions.

shapes.erl

Calculates perimeter, area and enclosing rectangle for different types shape:

  • { circle, { X, Y }, R }: circle (centre, radius)
  • { rectangle, { X, Y }, W, H } rectangle (centre, width, height)
-module( occurences ).
-export( [ occurences/1 ] ).
filter( _F, [] ) ->
[];
filter( F, [ X | Xs ] ) ->
case F( X ) of
true -> [ X | filter( F, Xs ) ];
_ -> filter( F, Xs )
end.