Skip to content

Instantly share code, notes, and snippets.

View khamidou's full-sized avatar
🎧

Karim Hamidou khamidou

🎧
View GitHub Profile
@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 / 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;
}
}
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"
@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
@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 / 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()
// 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 / top_level_domains.json
Last active March 2, 2016 23:35
A list of top-level domains in JSON format.
// Taken from Mozilla's Public Suffix List (https://publicsuffix.org/). License: MPL
domains = ["ac",
"com.ac",
"edu.ac",
"gov.ac",
"net.ac",
"mil.ac",
"org.ac",
"ad",
"nom.ad",
@khamidou
khamidou / list-events.php
Created April 9, 2018 19:18
Listing calendar events from the Nylas API using PHP and cURL
<?php
$ACCESS_TOKEN = "YOUR_ACCESS_TOKEN";
$ch = curl_init("https://api.nylas.com/events");
# Pass the access token as an HTTP basic auth username
curl_setopt($ch, CURLOPT_USERPWD, $ACCESS_TOKEN . ":");
# Return response instead of printing.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@khamidou
khamidou / create-event.php
Created April 9, 2018 19:19
Creating a calendar event using the Nylas API with PHP and cURL
<?php
$ACCESS_TOKEN = "YOUR_ACCESS_TOKEN";
$CALENDAR_ID = "The id of a calendar you got from the Nylas /calendars API";
$ch = curl_init("https://api.nylas.com/events");
# Setup request to send json via POST.
$payload = json_encode(
array("title" => "Alan Turing Birthdate",
"description" => "Alan Turing Birthdate",