Skip to content

Instantly share code, notes, and snippets.

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

Barthelemy Dagenais bartdag

💭
🏓 🐨 💡
View GitHub Profile
@bartdag
bartdag / README.md
Created October 22, 2017 01:06
Py4J - Multiple GatewayServer and CallbackServer instances

Py4J Multiple GatewayServer and CallbackServer instances

Compile and run TestApplication.java with py4j.jar in your classpath.

Then execute python3 test.py

Explanations

This creates three pairs of GatewayServer and CallbackServer with different ports on both the Java and Python sides. Python is driving the communication by asking Java to print

from contextlib import contextmanager
import logging
logger = logging.getLogger("root")
class History(object):
def __init__(self, value):
self.value = value
@bartdag
bartdag / ExampleListener.java
Created March 12, 2016 01:58
Py4J Listener Callback Example
package py4j.examples;
public interface ExampleListener {
Object notify(Object source);
}
@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:

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 / .gitattributes
Created December 6, 2013 13:04
merge po file
*.po merge=pofile
*.pot merge=pofile
@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 / 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 / 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 / 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.