Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Wheeler benjiwheeler

View GitHub Profile
@benjiwheeler
benjiwheeler / threadtest.py
Last active Feb 1, 2021
python thread test
View threadtest.py
import time
import timeit
from multiprocessing.dummy import (Pool, TimeoutError)
def delay(mynum, delay_secs):
print("starting #%s" % mynum)
time.sleep(delay_secs)
print("done with #%s" % mynum)
return True
@benjiwheeler
benjiwheeler / layout_boilerplate.html
Last active Jan 21, 2021
HTML, CSS layout boilerplate with header, footer, responsive content width; source https://jsbin.com/tocuguw
View layout_boilerplate.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-git.js"></script>
<script language="JavaScript">
$( document ).ready(function() {
$("#add").on("click", function() {
@benjiwheeler
benjiwheeler / selenium_browse_back.js
Created Dec 19, 2018
Selenium test code for browsing back and confirming that page is gone
View selenium_browse_back.js
elementIsVisible (element) {
return this.driver.wait(until.elementIsVisible(element));
}
elementIsNotVisible (element) {
return this.driver.wait(until.elementIsNotVisible(element));
}
const abbyElement = await findByText('Abby'); // Should show editor for new costume
await elementIsVisible(abbyElement);
@benjiwheeler
benjiwheeler / selenium_wait_until_clickable.js
Last active Dec 19, 2018
selenium js 3.6 attempt to wait until element is clickable
View selenium_wait_until_clickable.js
const costumesTabElement = await findByText('Costumes');
await driver.wait(() => {
return costumesTabElement.isDisplayed().then(displayed => {
console.log('got here A');
if (!displayed) return false;
console.log('got here B');
// costumesTabElement.click();
return costumesTabElement.isEnabled();
});
@benjiwheeler
benjiwheeler / time_utils.py
Last active Feb 2, 2018
Python time utils
View time_utils.py
import datetime
import pytz
# careful, don't assume now() is nyc time! on ec2, it's utc time.
def datetime_from_tz_naive_nyc_to_tz_aware_utc(nyc_datetime_tz_naive):
nyc_datetime_tz_aware = pytz.timezone('US/Eastern').localize(nyc_datetime_tz_naive)
return nyc_datetime_tz_aware.astimezone(pytz.utc)
def utc_tz_aware(utc_datetime_tz_naive):
return pytz.timezone('UTC').localize(utc_datetime_tz_naive)
@benjiwheeler
benjiwheeler / groups_controller_test.rb
Last active Jan 19, 2018
Example of Test::Unit code from Underground rails application, using FactoryGirl to generate test objects
View groups_controller_test.rb
require 'test_helper'
class GroupsControllerTest < ActionController::TestCase
test "ok to create duplicate group through api" do
user = create(:user)
@request.env["HTTP_AUTHORIZATION"] = user.basic_auth_header("abc1234")
post :apicreate, format: :json, nickname: "hannabarbera"
assert_response :created
assert_not_nil assigns(:group)
@benjiwheeler
benjiwheeler / zip2tz.csv
Last active Aug 13, 2017
Zip to Time Zone csv
View zip2tz.csv
We can't make this file beautiful and searchable because it's too large.
'00501','Holtsville','NY','America/New_York'
'00544','Holtsville','NY','America/New_York'
'01001','Agawam','MA','America/New_York'
'01002','Amherst','MA','America/New_York'
'01003','Amherst','MA','America/New_York'
'01004','Amherst','MA','America/New_York'
'01005','Barre','MA','America/New_York'
'01007','Belchertown','MA','America/New_York'
'01008','Blandford','MA','America/New_York'
@benjiwheeler
benjiwheeler / .gitignore
Last active May 10, 2017
.gitignore canonical
View .gitignore
# originally copied from https://help.github.com/articles/ignoring-files
# i manually keep this in sync with https://gist.github.com/benjiwheeler/d100b0c4ed7fbce3dfce
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
@benjiwheeler
benjiwheeler / Gemfile
Last active Jul 22, 2016
Gemfile canonical
View Gemfile
#######################################
# CANONICAL GEMS
# lives at https://gist.githubusercontent.com/brw12/d508024dcd7e230e4a88/raw/2e65efe2a145dda7ee51d1741299f848e5bf752e/Gemfile
#######################################
#######################################
# CORE SETUP
#######################
# core setup
source 'https://rubygems.org'
@benjiwheeler
benjiwheeler / angularJsonDataService.js
Last active May 18, 2016
Angular Service to share JSON data among controllers
View angularJsonDataService.js
// data.json could look like:
// {
// "menu": [{"name": "Contact Us"}, {"name": "About Us"}]
// }
// app.js could look like:
var app = angular.module('myApp');
app.factory('commonData', ['$http', '$q', function($http, $q){