Skip to content

Instantly share code, notes, and snippets.

@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 / float-compare
Created March 17, 2014 15:46
comparing floats
epsilon = .000001
x1 and x2 are equal if (fabs(x1 - x2) < epsilon)
@armstrongnate
armstrongnate / android-toast
Created March 26, 2014 16:19
android toast
Toast.makeText(getActivity().getApplicationContext(), "in onResume",
Toast.LENGTH_LONG).show();
@armstrongnate
armstrongnate / java-string-formatting
Created April 24, 2014 04:36
java string formatting
// formatting numbers
// => "1.2"
String.format("%s", new DecimalFormat("#.##").format(1.2))
// => "1.20"
String.format("%.2f", 1.2)
@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
@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 / 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

Bash inside of ubuntu image

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

On boot

boot2docker up
@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
@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.
}