Skip to content

Instantly share code, notes, and snippets.

🔍
Searching...

James Socol jsocol

🔍
Searching...
Block or report user

Report or block jsocol

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jsocol
jsocol / ex_test.go
Created Jul 22, 2019
#golang test subcases
View ex_test.go
package ex
import (
"fmt"
"testing"
)
func Multiplier(in int) int {
return in * 2
}
View dice.py
import functools
import operator
import random
class D():
"""A die.
Simulates an n-sided die, e.g. to create a d6, pass 6:
@jsocol
jsocol / finally.js
Last active Apr 23, 2018
finally example
View finally.js
async function batchFunctionFinally(commands) {
const batchStats = this.startBatch(commands)
let error = null
let response = null
try {
response = await this.redis.multi(commands)
} catch (e) {
error = e
throw e
} finally {
View mkpw.py
#!/usr/bin/env python
from __future__ import absolute_import, print_function, unicode_literals
import argparse
import random
import re
import string
sr = random.SystemRandom()
@jsocol
jsocol / async.js
Last active Apr 14, 2017
throwing from callbacks
View async.js
// Logs 'rejected Error: sync error'
const p = new Promise((resolve, reject) => {
throw new Error('sync error');
}).then(null, e => console.log('rejected', e));
// q never settles, uncaught error
const q = new Promise((resolve, reject) => {
setImmediate(() => { throw new Error('async error'); });
}).then(null, e => console.log('rejected', e));
View postfix.py
from __future__ import division, print_function, unicode_literals
import operator
import re
import sys
WHITESPACE_RE = re.compile(r'\s+')
NUMBER_RE = re.compile(r'-?\d+(\.\d+)?')
OPERATORS = {
View logger call site.js
'use strict';
var format = require('util').format;
function Logger() {
}
Logger.prototype.log = function $$Logger_log(msg) {
var context = this.getContext();
console.log(format('%s:%s:%s(%s): %s', context.pathname, context.lno, context.col, context.func, msg));
@jsocol
jsocol / test.diff
Created Dec 11, 2015
failing test for jingo#76
View test.diff
diff --git a/jingo/tests/jinja_app/helpers.py b/jingo/tests/jinja_app/helpers.py
new file mode 100644
index 0000000..62f344d
--- /dev/null
+++ b/jingo/tests/jinja_app/helpers.py
@@ -0,0 +1,8 @@
+from __future__ import absolute_import, unicode_literals
+
+from jingo import register
+
@jsocol
jsocol / classes.py
Created Jul 20, 2015
why new-style classes?
View classes.py
>>> class NewStyle(object):
... def foo(self):
... return 'foo'
>>> class OldStyle():
... def foo(self):
... return 'foo'
>>> dir(NewStyle)
['__class__',
View gist:5d523508410b011d4bc9
from boto.dynamodb2 import connect_to_region
from boto.provider import Provider
aws_settings_provider = Provider('aws')
def create_connection():
aws_region = # get the AWS region of the EC2 instance
# connect_to_region passes along the named arguments
# to the DynamoDBConnection class that gets created
You can’t perform that action at this time.