Skip to content

Instantly share code, notes, and snippets.

View khamidou's full-sized avatar
🎧

Karim Hamidou khamidou

🎧
View GitHub Profile
<form method = "POST" action="resultat.html"> {% csrf_token %}
<select name="entry_to_delete">
{% for product_name, product_id in history %}
<option value={{ product_id }}>{{ product_name }}</option>
{% endfor %}
</select>
<input type = "submit" value = "Submit">
</form>
from django.db import models
from django import forms
class Niveau(forms.Form):
choix_niveau=(
('deb', 'debutant'),
('int', 'intermédiaire'),
('av', 'avancé'))
niveau=forms.ChoiceField(choices=choix_niveau)

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@khamidou
khamidou / exponential_backoff.rb
Last active April 21, 2022 13:44 — forked from nathanl/exponential_backoff.rb
Exponential backoff with jitter in Ruby
# Exponential backoff in Ruby
begin
make_request
rescue RequestError => e
if retries <= max_retries
retries += 1
sleep 2 ** retries + rand(20)
retry
else
raise "Timeout: #{e.message}"
@khamidou
khamidou / verify_github.py
Created June 7, 2018 03:41
How to verify github webhooks
# Mostly cribbed from https://github.com/carlos-jenkins/python-github-webhooks/blob/759b67e3af8ed7334467b7d359cd00a10b0ac3c7/webhooks.py#L73
import hmac
def verify_github_webhook(secret, hub_signature_header, request_body):
sha_name, sha_value = hub_signature_header.split('=')
if sha_name != 'sha1':
raise ValueError('Unknown signature algorithm')
mac = hmac.new(secret.encode('utf-8'), msg=request_body, digestmod='sha1')
if not hmac.compare_digest(str(mac.hexdigest()), str(sha_value)):
@khamidou
khamidou / genjwt.py
Created May 24, 2018 16:12
How to generate Github API JWT tokens in Python
#!/usr/bin/env python3
#
# This is an example script that generates JWT tokens for the Github API.
# Usage: genjwt.py your_github_private_key.pem
#
# After getting a token, you can make curl requests to the API like this:
# curl -i -H "Authorization: Bearer JWT_TOKEN" -H "Accept: application/vnd.github.machine-man-preview+json" "https://api.github.com/app"
import sys
import jwt
import time
@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",
@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 / 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 / verify.rb
Last active September 28, 2021 13:20
Verifying Nylas webhooks using Ruby
require 'openssl'
# verify_webhook: check that a webhook was sent by a Nylas server.
# params:
# - request: the request object you get from Rails,
# - nylas_app_secret: your app secret.
def verify_webhook(request, nylas_app_secret)
digest = OpenSSL::Digest.new('sha256')
data = request.body.read
digest = OpenSSL::HMAC.hexdigest(digest, nylas_app_secret, data)