Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am mrcoles on github.
  • I am mrcoles (https://keybase.io/mrcoles) on keybase.
  • I have a public key whose fingerprint is 8832 F369 A11A 05DE B8A6 A2C1 977D 1CDA 6C93 9216

To claim this, I am signing this object:

@mrcoles
mrcoles / storage.py
Created Apr 23, 2015
StaticCachedS3BotoStorage - that reads its manifest.json locally
View storage.py
from django.conf import settings
from django.core.files.storage import get_storage_class
from compressor.cache import get_offline_manifest_filename
from storages.backends.s3boto import S3BotoStorage
class StaticCachedS3BotoStorage(S3BotoStorage):
"""
S3 storage backend that also saves files locally for django-compressor
@mrcoles
mrcoles / safekeypress.jquery.js
Created Apr 1, 2012
A reliable jQuery keypress event especially for arrow keys
View safekeypress.jquery.js
$.fn.safekeypress = function(func, cfg) {
cfg = $.extend({
stopKeys: {37:1, 38:1, 39:1, 40:1}
}, cfg);
function isStopKey(evt) {
var isStop = (cfg.stopKeys[evt.keyCode] || (cfg.moreStopKeys && cfg.moreStopKeys[evt.keyCode]));
if (isStop) evt.preventDefault();
return isStop;
@mrcoles
mrcoles / PressedKeys.js
Created Apr 11, 2012
A simple way to keep track of which keys are pressed at any one time.
View PressedKeys.js
var PressedKeys = function($elt) {
var pressed = {};
($elt || $(document)).on('keydown keyup', function(evt) {
pressed[evt.keyCode] = (evt.type == 'keydown');
});
return pressed;
};
// example
@mrcoles
mrcoles / mkdjangovirtualenv.sh
Created Oct 19, 2012
A bash script to setup various settings for a django virtualenv
View mkdjangovirtualenv.sh
#!/usr/bin/env bash
#
# Make a virtualenv specifically for a django project using virtualenvwrapper
#
# * Set the project directory in the .project file
# * Set the DJANGO_SETTINGS_MODULE and PYTHONPATH in postactivate
# * Install pip requirements if there's a requirements.txt file
# * Install git submodules if a git repo with submodules
#
@mrcoles
mrcoles / bson_pprint.py
Created Nov 14, 2012
A tool for pretty printing bson string (e.g., output of mongoexport)
View bson_pprint.py
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from bson import json_util, ObjectId
from bson.py3compat import string_types
from bson.dbref import DBRef
DEFAULT_INDENT = 4
@mrcoles
mrcoles / imports.less
Last active Dec 11, 2015
meteor less test example
@mrcoles
mrcoles / game.js
Last active Jan 5, 2018
Space creatures
View game.js
'use strict';
// Space Creatures
// ===============
//
// Involves:
//
// * Needs a game screen
// * alien creatures (3 different types)
// * a defender
@mrcoles
mrcoles / rc_fastai_setup.sh
Created Jan 16, 2018
Setup script for fast.ai on an rc cluster machine
View rc_fastai_setup.sh
#!/usr/bin/env bash
# derived from https://github.com/fastai/courses/blob/master/setup/install-gpu.sh
# exit on failed commands also print all commands
set -ex
cd $HOME
@mrcoles
mrcoles / offset.js
Created Jun 18, 2018
Compute the offset of a DOM element taking into account CSS transforms and scrolled parents.
View offset.js
export const computeOffset = elt => {
let rect = elt.getBoundingClientRect();
let width = rect.width;
let height = rect.height;
let left = 0;
let top = 0;
let offsetParent = elt;
while (offsetParent) {
left += offsetParent.offsetLeft;