Skip to content

Instantly share code, notes, and snippets.

View jasonaguilon-wf's full-sized avatar

Jason Aguilon jasonaguilon-wf

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jasonaguilon-wf
jasonaguilon-wf / make-available-port
Created June 8, 2018 17:35
Find a free port that could be used in a Makefile
# Scan for an available port.
# from https://github.com/Workiva/graph_app/compare/master...jasonaguilon-wf:make-test#diff-b67911656ef5d18c4ae36cb6741b7965R128
PORT ?= $(shell port=32768; while netstat -atn | grep -q :$$port; do port=$$(expr $$port + 1); done; echo $$port)
@jasonaguilon-wf
jasonaguilon-wf / worker_test.dart
Last active May 18, 2018 21:38
Example code that shows dart2js uses Web Worker to run a dart Isolate.
import 'dart:isolate' show Isolate, ReceivePort, SendPort;
import 'dart:js' as js show context, JsFunction, JsObject;
import 'package:test/test.dart';
js.JsObject currentWorker() {
js.JsFunction JsWorkerGlobalScope = js.context['WorkerGlobalScope'];
if (JsWorkerGlobalScope == null) return null;
@jasonaguilon-wf
jasonaguilon-wf / pre-commit
Last active April 11, 2016 21:47
git pre-commit hook for linting python and/or dart code. Copy this file into your project's `.git/hooks` directory.
#!/bin/sh
# Modified from kevincal version in https://gist.github.com/810399
# The following is a list of the most common PEP 8 errors and warnings; to
# skip some just add them to the IGNORE variable (comma separated):
# E111 indentation is not a multiple of four
# E123 closing bracket does not match indentation of opening bracket's line
# E201 whitespace after '('
# E202 whitespace before ')'
@jasonaguilon-wf
jasonaguilon-wf / ndb-repeated-vs-json
Created July 11, 2014 14:55
Comparing size of ndb repeated property with json property.
In [38]: ids = [uuid.uuid1().hex for n in range(20000)]
In [39]: class Foo(ndb.Model):
....: bar = ndb.TextProperty(compressed=True, repeated=True)
....: bazz = ndb.JsonProperty(compressed=True, json_type=list)
....:
In [40]: len(Foo(bar=ids)._to_pb().Encode())
Out[40]: 1218594
# reST py:function field info
def send_message(sender, recipient, message_body, priority=1)
"""Send a message to a recipient
:param str sender: The person sending the message
:param str recipient: The recipient of the message
:param str message_body: The body of the message
:param priority: The priority of the message, can be a number 1-5
:type priority: integer or None
:return: the message id
@jasonaguilon-wf
jasonaguilon-wf / lxml-find-vs-dict-get
Created January 6, 2014 16:47
lxml's find vs. dict's get
In [22]: root = etree.fromstring('<root xmlns:wf="http://tempuri.org/"><wf:a id="a"><wf:aa id="aa"/><wf:ab id="ab"/><wf:ac id="ac"/></wf:a></root>')
In [23]: d = {'a': root.find(".//{http://tempuri.org/}a[@id='a']")}
In [24]: %timeit root.find(".//{http://tempuri.org/}a[@id='a']")
100000 loops, best of 3: 2.96 µs per loop
In [25]: %timeit d.get('a')
10000000 loops, best of 3: 106 ns per loop
$ brew list -v
ack gource pkg-config
ant gradle pypy
apple-gcc42 harfbuzz python
autoconf icu4c rbenv
bash jpeg readline
boost lame reattach-to-user-namespace
cairo libass rtmpdump
colortail libevent ruby-build
cscope libffi sdl
@jasonaguilon-wf
jasonaguilon-wf / rbenv-doctor
Created October 28, 2013 19:11
rbenv doctor
$ curl -s https://gist.github.com/mislav/4728286/raw/rbenv-doctor.sh | bash -x 2>&1
+ rbenv --version
rbenv 0.4.0
+ rbenv versions
system
* 1.8.7-p374 (set by /Users/jason.aguilon/workspaces/docservices/bigsky/.ruby-version)
+ rbenv global
system
+ env
+ grep -E 'PATH|RUBY|BUNDLE|RBENV'
@jasonaguilon-wf
jasonaguilon-wf / datetime_util.py
Last active December 22, 2015 22:29
HOWTO: Globally patch a function
import datetime
def utcnow():
"""Return the current time.
Calls are forwarded to another method to enable gloablly patching this
function for tests.
"""
return _utcnow()