Skip to content

Instantly share code, notes, and snippets.

View bartdag's full-sized avatar
💭
🏓 🐨 💡

Barthelemy Dagenais bartdag

💭
🏓 🐨 💡
View GitHub Profile
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import py4j.GatewayServer;
public class OperatorExample {
// To prevent integer overflow
private final static int MAX = 1000;
@bartdag
bartdag / Application.java
Created June 30, 2011 19:21
Java: Getting FQNs from a simple name
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Main application/strategy
*/
public class Application {
@bartdag
bartdag / app.py
Created July 1, 2011 10:47
PyEnchant and multiprocessing
import sys
import enchant
from multiprocessing import Pool
if sys.version_info[0] < 3:
range = xrange
else:
range = range
@bartdag
bartdag / Java
Created July 7, 2011 19:18
Java and Python and Py4J
package p1;
import py4j.GatewayServer;
public class MyApplication {
public static void main(String[] args) {
GatewayServer server = new GatewayServer(null);
// This will start the Py4J server and now, the JVM is ready to receive Python commands.
@bartdag
bartdag / build.sh
Created April 16, 2012 12:19
Building uwsgi with python from homebrew
export CFLAGS="-Os -w -pipe -march=core2 -msse4 -arch x86_64"
export LDFLAGS="-arch x86_64"
pip install uwsgi-1.2-rc1.tar.gz
@bartdag
bartdag / cprofread.py
Created November 18, 2013 10:14
Basic python cprofile reader. Will print the 100 most time-consuming function calls (time and cumulative)
#!/usr/bin/python
import pstats
import sys
stats = pstats.Stats(sys.argv[1])
newstats = stats.sort_stats('time')
newstats.print_stats(100)
@bartdag
bartdag / cprofscanner.py
Created November 19, 2013 19:48
Python cprofile analyzer
#!/usr/bin/python
import argparse
from collections import namedtuple
import pstats
FunctionStats = namedtuple('FunctionStats', ['calls', 'tottime', 'cumtime',
'path', 'function_name', 'line_number', 'stat'])
@bartdag
bartdag / .gitattributes
Created December 6, 2013 13:04
merge po file
*.po merge=pofile
*.pot merge=pofile

Keybase proof

I hereby claim:

  • I am bartdag on github.
  • I am bartdag (https://keybase.io/bartdag) on keybase.
  • I have a public key whose fingerprint is EA6F 2C05 04A4 4379 8BD3 7E9A 7632 0A1B 9015 10C4

To claim this, I am signing this object:

@bartdag
bartdag / token_backend.py
Created April 30, 2015 14:02
Django REST Framework Token Authorization through get parameter
from rest_framework import authentication
from rest_framework import exceptions
class TokenParameterAuthentication(authentication.TokenAuthentication):
def authenticate(self, request):
token = request.GET.get('token')
if token == "":
msg = "Invalid token parameter. No credentials provided."
raise exceptions.AuthenticationFailed(msg)
elif not token: