Skip to content

Instantly share code, notes, and snippets.

View taylortrimble's full-sized avatar

Taylor Trimble taylortrimble

  • San Francisco, CA
  • 05:51 (UTC -07:00)
View GitHub Profile
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.lastField) {
[theTextField resignFirstResponder];
// scroll back to normal
} else if (theTextField == self.firstField) {
[self.secondField becomeFirstResponder];
// Scroll to second text field
} else if (theTextField == self.secondField) {
[self.lastField becomeFirstResponder];
// Scroll to last text field
@taylortrimble
taylortrimble / sspadd_gen.rb
Last active December 20, 2015 19:29
I just want it to spit out SSPADD for my current use case. There is only one "formula", but I'll make it extensible. I tried to make this a full Ruby repo at one point, but it's more of a Gist. 😄
# I just want it to spit out SSPADD for my current use case. There is only one "formula", but I'll make it extensible.
def get_bits(number_of_bits_you_have, fosc, target_speed, formula) # returns SSPADD
case formula
when :master
result = (fosc / (4 * target_speed)) - 1
else
# bad news bears
end
if result >= 2 ** number_of_bits_you_have
@taylortrimble
taylortrimble / cdir.py
Last active December 20, 2015 01:09
cdid.py recursively prints the contents of the directory with indentation and without stuttering. If the only contents of a given directory are another single directory, that single directory is concatenated instead of indented on the next line.
#!/usr/bin/env python
import os
import sys
# print_compact_dir recursively prints the contents of the directory with indentation and without stuttering.
# If the only contents of a given directory are another single directory, that single directory is concatenated instead of indented on the next line.
def print_compact_dir(root, route, level):
dir_path = os.path.join(root, route)
contents = os.listdir(dir_path)

Step by Step

Getting Kicked Off

  1. rails new app-name --skip-test-unit
  2. Better get the Gemfile looking spiffy/installed
  3. Don't forget to get all set up for PostgreSQL
  4. Use RSpec: rails generate rspec:install
@taylortrimble
taylortrimble / speech.rb
Created March 1, 2013 03:33
Testing out some voices for Fido, our new interactive lab assistant (Hubot-based!)
names = %w[Samantha Jill Trinoids Alex Tom Sangeeta]
phrases = [ "Access Denied.",
"The door is not responding. Please try using the manual lock.",
"The band saw has been activated. Please be safe!",
"Playing songs by Thin Lizzy.",
"Access granted." ]
all_phrases = phrases.join " "
@taylortrimble
taylortrimble / csv.rb
Created January 23, 2013 21:54
I needed to convert a nasty text document with formatted emails to CSV, so I made this.
require 'csv'
class User
attr_accessor :email, :first_name, :last_name
def initialize(email = nil, first_name = nil, last_name = nil)
@email = email
@first_name = first_name
@last_name = last_name
end
@taylortrimble
taylortrimble / escape-spaces.rb
Created January 23, 2013 21:52
I needed to put a leading backslash before spaces to make my shell happy, so I made this.
repos = File::open( "/Users/Trimble/Desktop/r", "r" ).read
output_file = File::open( "/Users/Trimble/Desktop/er.txt", "w" )
repos.each_line do |line|
output_file.puts line.gsub(' ', '\ ')
end
@taylortrimble
taylortrimble / Makefile
Last active October 13, 2015 14:28
C Makefile
#
# Makefile
# project
#
# Created by Taylor Trimble on 12/12/12.
# Copyright (c) 2013 Taylor Trimble.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
@taylortrimble
taylortrimble / spag.c
Created October 1, 2012 01:59
Spaghetti
for (int j = 0; j < node->numberOfDependants; ++j) {
++((&((*newNodes)[node->dependants[j]]))->numberOfPrerequisites);
}
@taylortrimble
taylortrimble / gradient.m
Created August 15, 2012 03:39
Radial Gradient
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
const CGFloat components[8] = {0.0, 0.4, 0.0, 1.0,
0.0, 0.4, 0.0, 1.0};
const CGFloat locations[2] = {0.0, 1.0};
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);