Skip to content

Instantly share code, notes, and snippets.

View ewjoachim's full-sized avatar
🐍
👨‍💻

Joachim Jablon ewjoachim

🐍
👨‍💻
View GitHub Profile
@ewjoachim
ewjoachim / format.js
Last active December 29, 2015 17:18
Python's.format for Javascript
String.prototype.format = function (obj) {
/**
* Does the same as a simple form of python "".format
* that will not work for anything else than number or string.
* Array form :
* "I have {} replacements to {}".format("two", "make")
* "I have {} replacements to {}".format(["two", "make"])
* "I have {0} replacements to {1}".format(["two", "make"])
* Dict form :
* "Hello {name} !".format({name: "Bob"});
@ewjoachim
ewjoachim / Class.js
Last active August 29, 2015 14:02
Base class for Javascript
define(["jq"], function($){
"use strict";
var Class = function(){};
var minimal_class_definition =
{
init: function()
{
}
};
var extend = function (base_class, additionnal_definition)
@ewjoachim
ewjoachim / puzzle.ipynb
Created March 14, 2015 19:13
Reddit Image puzzle
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def get_linked_objects(obj):
"""
Returns all the objects that would be deleted if a cascade deletion were to be done.
"""
links = [rel.get_accessor_name() for rel in obj._meta.get_all_related_objects()]
return [liked_obj for link in links for liked_obj in getattr(obj, link).all()]
@ewjoachim
ewjoachim / comprehension.ipynb
Created September 14, 2015 08:47
Comprehensions
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ewjoachim
ewjoachim / debug.py
Created September 14, 2015 11:06
Debug in place
import inspect
def debug():
"""
Anywhere in the code:
debug() # opens ipython shell
"""
from IPython.terminal.embed import InteractiveShellEmbed
ipshell = InteractiveShellEmbed()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ewjoachim
ewjoachim / ipynb_to_jekyll.py
Last active May 15, 2016 12:21
Jupyter Notebook to Jekyll (GHP)
#!/usr/bin/env python3
# coding=utf-8
"""
Borrowed and updated from
https://adamj.eu/tech/2014/09/21/using-ipython-notebook-to-write-jekyll-blog-posts/
"""
from __future__ import print_function
@ewjoachim
ewjoachim / distance.py
Last active July 12, 2016 15:46
Meetup Lille.py 12 juillet
from math import cos, sin, radians, atan2, sqrt
radius = 6371 # km
def distance(origin, destination):
"""
Determine distance between 2 sets of [lat,lon] in km
"""