Skip to content

Instantly share code, notes, and snippets.

@armstrongnate
armstrongnate / fetched-results-controller.swift
Last active August 29, 2015 14:19
UITableViewController with NSFetchedResultsController boilerplate
//
// MyViewController.swift
//
// Created by Nate Armstrong on 4/15/15.
// Copyright (c) 2015 Nate Armstrong. All rights reserved.
//
import UIKit
import CoreData
@armstrongnate
armstrongnate / setup-tab-bar-item.swift
Last active August 29, 2015 14:18
UIViewController extension for setting tabBarItem
// usage
class MyViewController: UIViewController {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupTabBarItem("entries")
}
}
// where "entries" is the name of the image.
// should have 2 images named tabbar-entries and tabbar-entries-selected
@armstrongnate
armstrongnate / navigationBarAppearance.swift
Last active August 29, 2015 14:13
custom navigation controller colors
let navigationBarAppearance = UINavigationBar.appearance()
navigationBarAppearance.barTintColor = UIColor(red:170.0/255.0, green:65.0/255.0, blue:65.0/255.0, alpha:1.0)
navigationBarAppearance.tintColor = UIColor.whiteColor()
navigationBarAppearance.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
@armstrongnate
armstrongnate / csv_to_json.rb
Created December 19, 2014 17:25
convert a csv file to json
require 'csv'
require 'json'
date = 5
file_name = "weather-2014-12-#{date}"
body = File.open("/path/to/file/#{file_name}.csv", 'rb').read
csv = CSV.new(body, :headers => true, :header_converters => :symbol, :converters => :all)
weather = csv.to_a.map {|row| row.to_hash }
File.open("/path/to/file/#{file_name}.json", 'w') { |f| f.write(weather.to_json) }
@armstrongnate
armstrongnate / uiview_init.swift
Created December 6, 2014 19:47
UIView subclass initialization
// when the view is wired up using Storyboard and a custom xib, initWithCoder is called.
class MyViewController: UIViewController {
@IBOutlet var myView: MyView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@armstrongnate
armstrongnate / DockerFile
Last active August 29, 2015 14:07
PHP and Apache on Docker
FROM ubuntu:latest
MAINTAINER Your Name <yourEmail@email.com>
RUN apt-get update
RUN apt-get -y upgrade
# Install apache, PHP, and supplimentary programs. curl and lynx-cur are for debugging the container.
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl curl lynx-cur

Bash inside of ubuntu image

docker run -it -v /Users:/Users ubuntu bash

On boot

boot2docker up
@armstrongnate
armstrongnate / vim_notes.md
Created August 26, 2014 03:43
some vim notes

Editing

Command(s) Description
o and O insert new line below and above respectively.
dd delete current line
x delete highlighted character
shift+x delete character to left
dw delete a word
de delete to end of word
/ to search, then n or N to go forward and back in results
@armstrongnate
armstrongnate / cherry-pick-migration.rb
Last active August 29, 2015 14:04
Cherry pick a migration
## One way to do it is from the rails console:
require 'db/migrate/MIGRATION_FILE_NAME.rb'
# if using def change
MigrationClass.new.migrate(:down)
# if using up or down
MigrationClass.up
## Another way is using a rake task
@armstrongnate
armstrongnate / post.rb
Last active August 29, 2015 14:03
example of a many to many relationship in rails
class Post < ActiveRecord::Base
has_many :post_tags
has_many :tags, through: :post_tags
end