Skip to content

Instantly share code, notes, and snippets.

View jrdmcgr's full-sized avatar

Jared McGuire jrdmcgr

  • Qgiv
  • Central Florida, USA
  • 06:15 (UTC -04:00)
View GitHub Profile
import string
def is_pangram(sentence):
"""
A pangram is a sentence that contains every letter of the alphabet. This
function determines whether the given sentence is a pangram.
>>> is_pangram('the quick brown fox jumps over the lazy dog')
True
"""
@jrdmcgr
jrdmcgr / js-adventures1.md
Last active August 29, 2015 13:57
Adventures in the JS Console: What happens when you do math with Javascript arrays?
> [] * []
0

Why is this?

Because, it seems that [] gets cast to a 0 when performing arithmetic.

$ ansible vagrant -a 'ls /home'
vagrant-host | success | rc=0 >>
vagrant
$ ansible vagrant -a 'cd /home'
vagrant-host | FAILED | rc=2 >>
[Errno 2] No such file or directory
@jrdmcgr
jrdmcgr / docker-build.sh
Created February 7, 2014 14:59
Why won't docker build?
$ tree
.
├── Dockerfile
├── index.html
├── index.js
└── package.json
$ docker build .
Uploading context 6.144 kB
Uploading context
@jrdmcgr
jrdmcgr / parallel.py
Created January 3, 2014 18:56
A crappy comparison of python parallelism libraries that implement a `Pool.map` method. Inspired by this article: https://medium.com/p/40e9b2b36148
from urllib2 import urlopen
from multiprocessing.pool import ThreadPool
from multiprocessing.pool import Pool
from gevent.pool import Pool as GEPool
from timeit import timeit
from pprint import pprint
urls = [
'http://www.python.org',
@jrdmcgr
jrdmcgr / sdl-test.c
Created October 31, 2013 16:49
Move a red square around with the arrow keys.
#include "SDL2/SDL.h"
#include <stdio.h>
void clear(SDL_Renderer * renderer) {
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
@jrdmcgr
jrdmcgr / halbig.py
Created October 7, 2013 13:33
A programming challenge
"""
Write logic that dynamically outputs a string of 35 characters.
The string is composed of 7 distinct letters. Each letter is used 5 times.
Any subset of 3 characters must be unique from any other subset of 3 characters.
Any subset of 3 characters can only have zero or ONE of the same letter.
"""
from collections import Counter
from itertools import permutations
def sequences(seq, n=3):
@jrdmcgr
jrdmcgr / mustache-recursive.html
Created June 19, 2013 18:28
Recursive partial in mustache.js
<html>
<body>
<div id="hierarchy"></div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.7.2/mustache.min.js"></script>
<script type="text/template" id="recursive-partial">
{{#children}}
<li>{{name}}
import re
from operator import *
def lisp(s_exp):
""" Evaluate pseudo-lisp.
`s_exp` should be a string of an s-expression.
If the first item in the s-exp isn't callable then the s-exp will be
treated like a literal list.
from types import MethodType
from functools import wraps
def decorate_methods(decorator):
"""
Return a class decorator that will decorate public methods with the given decorator.
"""
def class_decorator(klass):
for name in dir(klass):
if name.startswith('_'):