Skip to content

Instantly share code, notes, and snippets.

View majgis's full-sized avatar

Michael Jackson majgis

View GitHub Profile
@majgis
majgis / LICENSE
Last active December 10, 2015 19:29
BSD 2-Clause license for Michael A. Jackson which applies to all gists.
Copyright (c) 2012, Michael A. Jackson
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
@majgis
majgis / expire_date.py
Created January 9, 2013 01:55
construct a relativedelta from string argument
expire_deltas = {
'minutes': frdelta.FWD_MIN,
'hours' : frdelta.FWD_HR,
'days': frdelta.FWD_DAY,
'months': frdelta.FWD_MO,
'years': frdelta.FWD_YR,
}
def GetExpireDate(expire_date='months', now=None):
"""Convert expire_date arguments to date
@majgis
majgis / safe.py
Last active December 10, 2015 20:49
Safely access mutable attributes on class based configurations.
""" Inherit SafeReadOnly for safe access to mutable objects on classes
* Deep copy of mutable attributes on accessing uninstantiated class
* No assignment to class attributes on uninstantiated class
* Deep copy of mutable attributes when class is instantiated
"""
from collections import Hashable
@majgis
majgis / managers.py
Created January 16, 2013 16:26
Add new QuerySet methods using a Model inner class
from django.db import models
class QuerySetManager(models.Manager):
"""Add new QuerySet methods using a Model inner class
Reference:
http://djangosnippets.org/snippets/734/
"""
@majgis
majgis / while.js
Created February 21, 2013 17:09
Javascript while loop to deplete an array from either direction.
var x = [1,2,3]
//back to front
while(x.length){
var value = x.pop();
console.log(value);
}
//array is now empty, lets replace it
var x = [1,2,3]
@majgis
majgis / interview.py
Last active December 16, 2015 19:28
Answer to an interview question.
""" Interview question
Write a method that takes a string, and returns the string in reverse.
For instance, if passed abc123 it should return 321cba
"""
class StringUtil(object):
""" Utility for strings
@majgis
majgis / collection.py
Last active December 17, 2015 01:38
A defaultnamedtuple which creates a namedtuple with default values when none are given.
""" Additional collections to augment Python's collections module.
"""
from collections import namedtuple
def defaultnamedtuple(
typename,
field_names,
verbose=False,
rename=False,
@majgis
majgis / gist:9558866
Created March 14, 2014 23:04
npm shrinkwrap
#-- Start pm-ops-utils dev --#
# Remove local modules and npm cache
alias npmPurge="
rm -rf node_modules
npm cache clean
"
# Ugly, but it is a fail-safe way of generating npm-shrinkwrap.json
alias updateShrinkwrap="
@majgis
majgis / gist:9680084
Last active August 29, 2015 13:57
Rough Node.js Hierarchical Queue
var http = require('http');
function RequestQueue() {
this._maxRequests = 3;
this._pendingCount = 0;
this._queue = [];
this.count = 0;
this._uriInQueue = {};
}
@majgis
majgis / gulpfile.js
Created November 23, 2014 08:36
find protractor selenium jar
var gulp = require('gulp');
var lib = require('./lib');
var protractor = require("gulp-protractor").protractor;
var jarPath = lib.getProtractorSeleniumJarPath();
gulp.task('default', function(){
gulp.src(["./spec/*.js"])
.pipe(protractor({
configFile: "protractor.config.js",