Skip to content

Instantly share code, notes, and snippets.

View rickcnagy's full-sized avatar

Rick Nagy rickcnagy

View GitHub Profile
@rickcnagy
rickcnagy / gitmaster.sh
Last active December 19, 2015 10:39
Git reset to match master
git stash && git fetch origin && git reset --hard origin/master
@rickcnagy
rickcnagy / croncd.py
Last active December 19, 2015 10:39
chdir to script's actual path in Python 2.7 - necessary when firing scripts from cron
#cd to the script's directory in case it is not the current working directory
os.chdir(os.path.dirname(os.path.abspath(__file__)))
@rickcnagy
rickcnagy / setup.py
Last active December 19, 2015 13:29
Create password file on disk to access web services from
# ADD PASSWORDS.P TO .gitignore IF USING GITHUB!!
import cPickle
def main():
all_info = {'USERNAME': raw_input("username: "),
'PASSWORD': raw_input("password: ")}
cPickle.dump(all_info, open("passwords.p", "w"))
@rickcnagy
rickcnagy / read_passwords.py
Last active December 19, 2015 13:29
Read the passwords saved to disk in setup.py
class Passwords(object):
def __init__(self):
try:
passwords = cPickle.load(open("passwords.p"))
except (EOFError, IOError):
sys.exit("No password file (./passwords.p) found. Please run 'setup.py'.")
self.USERNAME = passwords['USERNAME']
self.PASSWORD = passwords['PASSWORD']
@rickcnagy
rickcnagy / randomBool.c
Created July 22, 2013 12:46
inline random boolean generator
if (arc4random() % 2) {
// do something
}
@rickcnagy
rickcnagy / ViewControllerInit.c
Created July 28, 2013 00:29
Methods to initiate view controller somehow *before* viewDidLoad - not usually necessary. From lecture 5 (47:00) of Standard CS193P Winter/Spring 2013
- (void) setup
{
// init that can't wait for viewDidLoad
}
- (void) awakeFromNib
{
[self setup];
}
@rickcnagy
rickcnagy / missing_copyfiles.py
Last active December 20, 2015 11:49
Quick command line Python script to check which files/folders are missing from a copied directory
import os
original_path = raw_input("Full path of original folder: ")
duplicate_path = raw_input("Full path of folder that files were copied to: ")
for _, __, file in os.walk(original_path):
original = file
for _, __, file in os.walk(duplicate_path):
duplicate = file
@rickcnagy
rickcnagy / arrayReverse.c
Created August 1, 2013 20:23
Simple code to reverse an array, just like reverse() in Python. From http://simplyhacking.com/reverse-array-in-objc.html
NSArray *reversedArray = [[array reverseObjectEnumerator] allObjects];
@rickcnagy
rickcnagy / QuizInterfaceSubclass.js
Created November 9, 2013 21:59
Subclass for QuizInterface outline for qs-quizzes
function QuizEditor(sender, quiz)
{
this.sender = sender;
this.quiz = quiz;
ClassUtil.inherit(QuizEditor, this, QuizInterface)
this.initialize();
}
@rickcnagy
rickcnagy / PDFEMailBodyUpload.js
Last active December 28, 2015 12:49
Short Google Apps Script to email all files marked as notUploaded to an email address, such as a Box.com email upload address
// for Google Apps Script
function gmailPDFUpload ()
{
var uploadedLabel = GmailApp.getUserLabelByName('uploaded');
var notUploadedLabel = GmailApp.getUserLabelByName('notUploaded');
var notUploadedThreads = notUploadedLabel.getThreads();
for (index in notUploadedThreads) {