Skip to content

Instantly share code, notes, and snippets.

@dbreunig
dbreunig / gist:1967518
Created March 3, 2012 19:00
NSString Category Method: NSDate from Twitter Date String
@interface NSString (Twitter)
- (NSDate*)twitterDate;
@end
@implementation NSString (Twitter)
- (NSDate*)twitterDate
{
@dbreunig
dbreunig / ReporterSaveFileDescription.md
Last active January 22, 2021 16:07
A description of the data written to the Reporter App Dropbox save folder.

#Reporter Save File Schema

##The Reporter Export File

Reporter saves to your Dropbox account with plaintext JSON files, one for each day. When a Report is entered in the app a file is created for that day if it does not exist. Otherwise, the report is appended to the existing file. The save folder is located in 'Dropbox/Apps/Reporter-App/'.

Reporter save files are named according to the following convention:

YYYY-MM-DD-reporter-export.json
@dbreunig
dbreunig / DABDecayingAnimationInterval.m
Last active August 29, 2015 13:56
A method which returns a time interval, adjusted for time since initial method call. The caller specifies the initial time (the speed at which an animation might run during first run) and an eventual time (which the time interval will decay towards). Set the kTotalDecayTime to the number of days it will take for the time interval to fully decay.…
#define kInitialAnimationDate @"InitialAnimationDate"
#define kTotalDecayTime 14 // Number of days for initialTime to decay to eventual time
+ (NSTimeInterval)intervalStartingFrom:(NSTimeInterval)initialTime decayingTowards:(NSTimeInterval)eventualTime
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDate *creationDate = [defaults objectForKey:kInitialAnimationDate];
NSUInteger currentAge;
// Create the date if it hasn't been saved yet
@dbreunig
dbreunig / psv2csv.rb
Last active January 20, 2020 03:55
A quick and dirty script to convert pipe separated files (PSV) to comma separated files (CSV)
require 'csv'
psv_file = ARGV[0]
csv_loc = ARGV[1]
if psv_file =~ /psv/ && csv_loc =~ /csv/
CSV.open(csv_loc, "wb") do |csv|
File.open(psv_file, "r").each_line do |line|
row = line.split('|')
csv << row
@dbreunig
dbreunig / dmacode2dmaname.rb
Created August 23, 2018 18:43
A quick and dirty script for adding DMA names to a CSV containing DMA codes.
#!/usr/bin/env ruby
# ----------------------------------------
# DESCRIPTION
# This script takes in a CSV file containing a column with DMA code numbers.
# It outputs to stdout a CSV file exactly like the input file but with a
# column of associated DMA names appended.
#
# ISSUES:
@dbreunig
dbreunig / elevationDownloader.rb
Created January 20, 2019 03:22
A Ruby script to download elevation data and write it to a simple CSV.
# A script for obtaining elevation data.
# Using the docker image here: https://github.com/racemap/elevation-service
# Steps:
# $ docker run --rm -eTILE_SET_PATH=s3:// -p3000:3000 normanrz/elevation-service
# ruby elevationDownloader -s 35.035443,-111.040346 -f 35.016741,-111.005449 -p 0.001
require 'optparse'
require 'uri'
require 'net/http'
require 'json'
@dbreunig
dbreunig / qn.rb
Last active December 7, 2020 22:45
A script that creates a note with a specified, date stamped file name in a defined location, appends a divider and timestamp, then opens the file with TextEdit (macOS). This is what I'm reduced to now that Notational Velocity doesn't work so hot.
#!/usr/bin/env ruby
#
# qn stands for 'Quick Note.' This app quickly creates a text file
# in a hardcoded or specified directory with a default filename.
#
# The filename is {project}_YYYY-MM-DD.txt
#
# One file per day, per project is created. If the file exist, the
# new note is appended.
@dbreunig
dbreunig / jsoncsv.rb
Last active May 19, 2021 04:56
Extracting an array of similar hash objects from a JSON file into a csv, following some very basic assumptions.
#!/usr/bin/env ruby
# frozen_string_literal: true
require "json"
require "csv"
require "optionparser"
#
# Option Handling
#
require 'open-uri'
require 'date'
require 'csv'
# Add daily change column
def add_daily_change_column(table, column_name, new_column_name=nil)
new_column_name ||= column_name + "_change"
table.by_col![new_column_name] = table.by_col[column_name].each_cons(2).map { |a, b| b - a }.prepend(0)
table
end
@dbreunig
dbreunig / transcribe_to_sqlite.py
Created September 26, 2022 21:46
An example of transcribing an audio file with Whisper and loading its transcription data into a sqlite3 database for easy searching.
import whisper
import sqlite3
# Load the model. Pick from tiny, base, small, medium, large.
model = whisper.load_model("base")
# Transcribe the local file 'podcast.mp3'. Change as necessary
transcription = model.transcribe("podcast.mp3")
# Create the database and table