Skip to content

Instantly share code, notes, and snippets.

View khamidou's full-sized avatar
🎧

Karim Hamidou khamidou

🎧
View GitHub Profile
@khamidou
khamidou / vault-diff
Created December 3, 2015 21:47
A python script to diff ansible-vault files
#!/usr/bin/env python
import os
import sys
import optparse
def print_usage():
print "usage: vault-diff --vault-password file --rev1 revision1 --rev2 revision2 --file file"
def main():
parser = optparse.OptionParser()
@khamidou
khamidou / snippet.js
Created September 1, 2015 17:48
Nylas nodejs API example --- Creating an event
// Every event belongs to a calendar, so grab the first writable calendar
nylas.calendars.list({}).then(function(calendars) {
cal = null;
for(var i = 0; i < calendars.length; i++) {
if (calendars[i].readOnly != true) {
cal = calendars[i];
break;
}
}
@khamidou
khamidou / NylasAuthResponse.cs
Last active August 29, 2015 14:28 — forked from CiprianPorumbescu/NylasAuthResponse.cs
An example of how to authorize Nylas from .Net
public async Task<ActionResult> NylasAuthenticationResult(string code)
{
using (HttpClient httpClient = new HttpClient())
{
// tried as x-www-form-encoded
var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("client_id", "cf7jhxlkkvimkxvd2vnkkzci"));
postData.Add(new KeyValuePair<string, string>("client_secret", "your_secret"));
postData.Add(new KeyValuePair<string, string>("grant_type ", "authorization_code"));
@khamidou
khamidou / gist:6b7e8702f8fc0e8dd251
Last active February 28, 2022 08:57
Ever got a mysterious "IOError: cannot send to <Channel id=1 closed>" from pytest with xdist and gevent? Scroll to the comments to see how to solve it.
vagrant@precise64:/vagrant/tests$ py.test -n 2 general/
================================================= test session starts ==================================================
platform linux2 -- Python 2.7.3 -- py-1.4.26 -- pytest-2.6.4
plugins: xdist, httpretty
gw0 [24] / gw1 okINTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/local/lib/python2.7/dist-packages/_pytest/main.py", line 84, in wrap_session
INTERNALERROR> doit(config, session)
INTERNALERROR> File "/usr/local/lib/python2.7/dist-packages/_pytest/main.py", line 122, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 413, in __call__
// je fais une fonction pour calculer une correction sur des images
function composeImages($bottomImage, $topImage, $x, $y) {
$y_diff = $topImage->getImageHeight / 2; // ici j'oublie de mettre une parenthèse à mon appel de fonction
// ça passe parce que php met ça à 0
$corrected_y = $y - $y_diff; // du coup il n'y a pas de correction
// j'en déduis que ça marche et je m'autocongratule
@khamidou
khamidou / gist:2877088
Created June 5, 2012 19:12
An example filter
from django import template
from django.contrib.sites.models import Site
from urlparse import urlparse
import datetime
register = template.Library()
@register.filter(name='dayinweek', is_safe=True, expects_localtime=True)
def dayincurrentweek(day):
if day == datetime.date.today():
@khamidou
khamidou / Rakefile
Created February 3, 2012 19:39
Rakefile to concatenate templates and js files together
require 'rake'
task :default => :compile_templates
task :clean_compiled_file do
if File.exist?('release.js')
File.unlink('release.js')
end
end
def convert_overloaded_post(request):
"""
Convert a POST method with a hidden field
named _method to a PUT or a DELETE
"""
request._load_post_and_files()
if request.method == "POST":
if hasattr(request.POST, "_method"):
if request.POST["_method"] == "PUT":
request.method = "PUT"