Skip to content

Instantly share code, notes, and snippets.

View jrdmcgr's full-sized avatar

Jared McGuire jrdmcgr

  • Qgiv
  • Central Florida, USA
  • 07:34 (UTC -04:00)
View GitHub Profile
@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 / 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}}
@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 / debug
Created August 18, 2017 16:41
Vagrant not working on CygWin / Babun
{ ~ } » VAGRANT_DEBUG_LAUNCHER=1 vagrant --debug ~ 127
2017/08/18 12:33:04 launcher: path = C:\HashiCorp\Vagrant\bin\vagrant.exe
2017/08/18 12:33:04 launcher: installerDir = C:\HashiCorp\Vagrant
2017/08/18 12:33:04 launcher: embeddedDir = C:\HashiCorp\Vagrant\embedded
2017/08/18 12:33:04 launcher: gemPaths (initial) = []string{"C:\\HashiCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-1.9.7", "C:\\HashiCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-share-1.1.9"}
2017/08/18 12:33:04 launcher: bad gemPath += C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-share-1.1.9\lib\vagrant\version.rb
2017/08/18 12:33:04 launcher: gemPaths (final) = []string{"C:\\HashiCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-1.9.7"}
2017/08/18 12:33:04 launcher: gemPath = C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.9.7
2017/08/18 12:33:04 launcher: windows detected OS - cygwin
2017/08/18 12:33:04 launcher: env "CFLAGS" = ""
<?php
class Link
{
public function __construct($name, $url)
{
$this->name = $name;
$this->url = $url;
}
}
@jrdmcgr
jrdmcgr / packer.log
Last active August 19, 2016 17:04
Packer Issue
2016/08/19 12:51:36 [INFO] Packer version: 0.10.1
2016/08/19 12:51:36 Packer Target OS/Arch: darwin amd64
2016/08/19 12:51:36 Built with Go Version: go1.6.2
2016/08/19 12:51:36 Detected home directory from env var: /Users/jmcguire
2016/08/19 12:51:36 Using internal plugin for null
2016/08/19 12:51:36 Using internal plugin for virtualbox-iso
2016/08/19 12:51:36 Using internal plugin for amazon-chroot
2016/08/19 12:51:36 Using internal plugin for docker
2016/08/19 12:51:36 Using internal plugin for parallels-iso
2016/08/19 12:51:36 Using internal plugin for vmware-iso
create table exercise (
id integer primary key,
name varchar(50)
);
create table session (
id integer primary key,
date datetime
);

This now works with the latest Selenium bindings. (pip install selenium)

from selenium import webdriver
driver = webdriver.Firefox() # or webdriver.Chrome()
driver.get('http://user:password@example.com')

The eqivalent with Splinter doesn't work.

from splinter import Browser
browser = Browser()
@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):
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.