Skip to content

Instantly share code, notes, and snippets.

View jimbaker's full-sized avatar

Jim Baker jimbaker

View GitHub Profile
@jimbaker
jimbaker / lazy_reload.diff
Created May 11, 2016 16:33
Workaround for lazy_reload module on Jython; see https://github.com/boostpro/lazy_reload
diff --git a/lazy_reload.py b/lazy_reload.py
index 566521e..1694775 100644
--- a/lazy_reload.py
+++ b/lazy_reload.py
@@ -40,7 +40,10 @@ else:
modules_to_reload = {}
def is_submodule_name( name, root_name ):
- return (name + '.').startswith(root_name + '.')
+ try:
@jimbaker
jimbaker / socket-EALREADY.diff
Created November 13, 2015 22:10
Diff for socket.connect_ex to returning EALREADY when a socket connection is already in progress
diff -r 03f797ecd7ea Lib/_socket.py
--- a/Lib/_socket.py Thu Nov 12 13:47:41 2015 +1100
+++ b/Lib/_socket.py Fri Nov 13 15:08:47 2015 -0700
@@ -28,7 +28,8 @@
from java.util import NoSuchElementException
from java.util.concurrent import (
ArrayBlockingQueue, CopyOnWriteArrayList, CountDownLatch, LinkedBlockingQueue,
- RejectedExecutionException, ThreadFactory, TimeUnit)
+ ExecutionException, RejectedExecutionException, ThreadFactory,
+ TimeoutException, TimeUnit)
apply plugin: 'java'
version = '0.1'
jar { }
repositories {
mavenCentral()
}
dependencies {
@jimbaker
jimbaker / build.gradle
Created August 19, 2015 22:30
Gradle build script for Spark. Just enough integration to do something interesting - IntelliJ, shading, unit testing with Scala test, interop with Twilio SDK - without attempting to download the internet.
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '1.2.2'
}
apply plugin: 'idea'
apply plugin: 'scala'
apply plugin: 'com.github.johnrengelman.shadow'
version = 0.1
@jimbaker
jimbaker / blindtrust.py
Created April 14, 2015 18:51
Do not use this recipe for blindly trusting SSL certificates. However, I suppose if you really know what you're doing, it might be OK. But really, don't ;)
# Support blind trust of all certificates; useful for testing
import sys
from array import array
from javax.net.ssl import SSLContext, TrustManager, X509TrustManager
from java.net import URL
__all__ = ["trust_all_certificates"]
@jimbaker
jimbaker / gist:177da070a0e70b9ac97c
Created March 5, 2015 18:48
Expect to get java.net.ConnectException from the ChannelFuture, getting this exception printed and no return from the synced future
test_socket
testClosedSocket (test.test_socket.TestJythonTCPExceptions) ... 2015-03-05 11:34:33,260 MainThread DEBUG setsockopt Setting option 128 to 1 <_realsocket at 0x2 type=unknown open_count=1 channel=None timeout=None>
ok
testConnectionRefused (test.test_socket.TestJythonTCPExceptions) ... 2015-03-05 11:34:33,276 MainThread DEBUG setsockopt Setting option 128 to 1 <_realsocket at 0x3 type=unknown open_count=1 channel=None timeout=None>
2015-03-05 11:34:33,276 MainThread DEBUG _connect Begin connection to ('localhost', 50100) <_realsocket at 0x3 type=unknown open_count=1 channel=None timeout=None>
2015-03-05 11:34:33,286 MainThread DEBUG _get_jsockaddr Address localhost/127.0.0.1:50100 for ('localhost', 50100) *
2015-03-05 11:34:33,288 MainThread DEBUG __init__ Initializing inbound handler <_realsocket at 0x3 type=client open_count=1 channel=None timeout=None>
2015-03-05 11:34:33,290 MainThread DEBUG _connect Connect 0.0.0.0/0.0.0.0:0 to localhost/127.0.0.1:50100 <_realsocket at 0x3 type=client open_coun
@jimbaker
jimbaker / append-compare.py
Last active August 29, 2015 14:15
Write Avro output file by appending. Modified from https://gist.github.com/esheffield/3514988368eb42db1203
import datetime
import string
import random
import json
import sys
import avro.schema
from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter
@jimbaker
jimbaker / threading.diff
Created January 21, 2015 21:29
Print main thread name before theading.py clobbers it
diff -r 9c81bac53d7a Lib/threading.py
--- a/Lib/threading.py Tue Jan 20 22:06:52 2015 +0000
+++ b/Lib/threading.py Wed Jan 21 14:29:01 2015 -0700
@@ -274,6 +274,7 @@
class _MainThread(Thread):
def __init__(self):
+ print "main thread=%r" % (java.lang.Thread.currentThread().name,)
Thread.__init__(self, name="MainThread")
import atexit
@jimbaker
jimbaker / decompiled-fact.java
Created January 14, 2015 23:59
Decompilation of Jython module
import org.python.compiler.*;
import org.python.core.*;
@APIVersion(36)
@MTime(1421279812000L)
@Filename("fact.py")
public class fact$py extends PyFunctionTable implements PyRunnable
{
static fact$py self;
static final PyCode f$0;
@jimbaker
jimbaker / gist:f1f77dfa4b53a93b2d45
Created January 12, 2015 23:10
Jython uses a startup script, so it needs #!/path/to/env
$ jpip install pytest
Version: ImageMagick 6.8.9-8 Q16 x86_64 2014-10-23 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg ltdl lzma png xml zlib
Usage: import [options ...] [ file ]
Image Settings:
-adjoin join images into a single multi-image file