Skip to content

Instantly share code, notes, and snippets.

View apinstein's full-sized avatar

Alan Pinstein apinstein

  • Atlanta, GA
View GitHub Profile
@apinstein
apinstein / gist:92865ce7d479b50a2726
Created December 4, 2014 17:25
migrate php file sessions to dynamo
<?php
require 'conf/webapp.conf';
$sessionTableName = '';
$sessionLifetime = ini_get('session.gc_maxlifetime');
$sdir = '/opt/www/domains/tourbuzz/runtime/sessions'; // hard-code so it still works after switching live to dynamo
$awsKey = '';
$awsSecretKey = '';
@apinstein
apinstein / gist:6d69438df97f50e37cfa
Created December 25, 2014 05:31
Swift Promise example
// Example of a promise that could be used to wrap bracketed capture
import Foundation
import BrightFutures
func grabBrackets (n:Int) -> Future<[AnyObject]> {
let promise = Promise<[AnyObject]>()
var data = [AnyObject]()
virtualtour=> \d+ tour_event
Table "public.tour_event"
Column | Type | Modifiers | Storage | Stats target | Description
--------------------+-----------------------------+-----------------------------------------------------------------------------------+----------+--------------+-------------
tour_event_id | integer | not null default nextval(('public.tour_event_tour_event_id_seq'::text)::regclass) | plain | |
tour_event_type_id | integer | not null | plain | |
tour_id | integer | not null | plain | |
visitor_id | text |
@apinstein
apinstein / test-wifi.sh
Last active June 1, 2020 11:07
A simple shell script to test wifi connection over time and record data in a format for easy analysis.
#!/bin/zsh
# configure curl output format
echo '%{url_effective},%{time_namelookup},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{time_total}' > curltime.format
# configure postgres
echo "create table wifi_data (ssid text,url_effective text,time_namelookup numeric(9,5),time_connect numeric(9,5),time_appconnect numeric(9,5),time_pretransfer numeric(9,5),time_redirect numeric(9,5),time_starttransfer numeric(9,5),time_total numeric(9,5));"
echo ""
echo "\\\\copy wifi_data from './wifi-data.csv' DELIMITER ',' CSV HEADER"
echo "select ssid, count(*), avg(time_total), stddev(time_total), min(time_total), max(time_total) from wifi_data group by ssid having count(*) > 5;"
@apinstein
apinstein / .screenrc.local
Created January 12, 2016 15:09
screenrc for vagrant dev
chdir /opt/www/domains/tourbuzz/current
screen -t db 0 rake db
screen -t code 1
chdir /opt/www/domains/tourbuzz/shared/log
screen -t log 2
@apinstein
apinstein / factor.r
Created December 18, 2016 20:06
Plotting data via bin'd factors
## DEMO of appropriate way to bin variables with a factor
## this is particularly useful if one wants to bin things of asymmetric widths
## alternative would be non-linear axis
library(ggplot2)
library(grid)
library(gridExtra)
library(data.table)
r <- data.table(x = rgeom(1000, .01))
@apinstein
apinstein / gist:917346f203b68d06df7a19e4ed52a2f5
Created December 27, 2016 18:31
R data.table function issue
is_established_customerF <- function(customer_segment, credits_purchased) {
print(typeof(customer_segment)) # prints only once?
established_customer_threshold <- 100000000 # infinitely large
customer_segment <- as.character(customer_segment)
if (customer_segment == "multiple_photographer_company") {
established_customer_threshold <- 3000
} else if (customer_segment == "in_house_photography_department") {
established_customer_threshold <- 1000
} else if (customer_segment == "full_time_single_re_photographer") {
@apinstein
apinstein / gist:d94a85207ee015b2d82323cab885969f
Last active January 1, 2017 20:06
Stuff I put on my mac
# Markdown Quicklook plugin
port install qlmarkdown
# multiple clipboard
http://jumpcut.sourceforge.net
# don't go to sleep, sometimes
http://lightheadsw.com/caffeine/
@apinstein
apinstein / gist:cb2921cbc93530fda760d8556903eb3b
Last active September 29, 2021 14:18
Apps Script for Google Sheets to implement automatic UUID and LAST UPDATED features.
const headerRowI = 1; // the row with the header cols
const UUID_COLUMN_NAME = 'UUID'
const LAST_UPDATED_COLUMN_NAME = 'LAST UPDATED'
// ENTRY POINTS
// SHEET HOOK ENTRY POINTS
function onEdit(e) {
// Spreadsheet is the 'file', Sheet is the actual sheet, similar but incompatible APIs on different objects, quite the gotcha
var sheet = e.source.getActiveSheet();