Skip to content

Instantly share code, notes, and snippets.

@armstrongnate
armstrongnate / android-toast
Created March 26, 2014 16:19
android toast
Toast.makeText(getActivity().getApplicationContext(), "in onResume",
Toast.LENGTH_LONG).show();
@armstrongnate
armstrongnate / float-compare
Created March 17, 2014 15:46
comparing floats
epsilon = .000001
x1 and x2 are equal if (fabs(x1 - x2) < epsilon)
@armstrongnate
armstrongnate / time durations
Created February 20, 2014 16:19
Get hours, minutes, and seconds from time difference in ruby.
# t1 and t2 are Time objects
# t is a class with attributes hours, minutes, and seconds
diff = t2 - t1
%w(hours minutes seconds).each do |duration|
diff -= (t.send("#{duration}=", (diff / 1.send(duration)).round)).send(duration)
end
@armstrongnate
armstrongnate / ruby on mavericks
Created November 8, 2013 20:49
instal ruby on mavericks with rbenv
# XCode 5 hides these away:
export C_INCLUDE_PATH="$(xcrun --show-sdk-path)/usr/include"
export CPLUS_INCLUDE_PATH="$(xcrun --show-sdk-path)/usr/include"
export LIBRARY_PATH="$(xcrun --show-sdk-path)/usr/lib:$(xcrun --show-sdk-path)/usr/lib/system:$LIBRARY_PATH"
and then you can do rbenv install
class AddIndexOnCompanyIdInConcernsAndDepartmentsAndUsers < ActiveRecord::Migration
def change
add_index :departments, :company_id
add_index :concerns, :company_id
add_index :users, :company_id
end
end
@armstrongnate
armstrongnate / mysql start
Created June 26, 2013 23:40
start mysql after reboot
mysql.server start
@armstrongnate
armstrongnate / nsObjectInit
Last active December 18, 2015 01:19
base init method of NSObject
@implementation MyCustomClass
- (id)init
{
self = [super init];
if (self) {
// custom initializations
// use underscore assignment (_date = [NSDate date]) instead of setters and getters
@armstrongnate
armstrongnate / awakeFromNib
Created June 4, 2013 02:00
how to call awakeFromNib method inside View Controller (method that gets called before viewDidLoad, mostly used for geometry changes)
// the following class inherits from UIViewController
@implementation MyCustomViewController
- (void)setup
{
// initialization that can't wait until viewDidLoad
}
- (void)awakeFromNib
@armstrongnate
armstrongnate / rbenv 187 mountain lion
Created May 24, 2013 18:00
Install ruby 1.8.7 using rbenv on mountain lion.
Ultimately, this line did the trick:
$ CONFIGURE_OPTS="--without-tk" rbenv install 1.8.7-p370
Additional info:
https://github.com/sstephenson/ruby-build/issues/207
https://github.com/sstephenson/ruby-build/wiki#installing-187-on-os-x-108-mountain-lion
@armstrongnate
armstrongnate / json request objective c
Last active December 17, 2015 10:08
JSON HTTP request in objective-c
NSURL *wiresUrl = [NSURL URLWithString:@"http://blahblah.com.192.168.1.100.xip.io/stuff.json"];
NSData *jsonData = [NSData dataWithContentsOfURL:wiresUrl];
NSError *error = nil;
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];