Skip to content

Instantly share code, notes, and snippets.

@iamatypeofwalrus
iamatypeofwalrus / commands.md
Created September 3, 2014 18:17
Mac OS X -> Productivity Commands

Calendar

  • ⌘-t --> Go to Today

Terminal

  • ctrl-a --> go to beginning of terminal line
  • ctrl-e --> go to end of terminal line
  • alt-click --> go to character
@iamatypeofwalrus
iamatypeofwalrus / add_int_to_character.swift
Created July 21, 2014 18:16
A convoluted way to add an Integer to a Character and get another Character in Swift
// Per the BNR iOS programming guide's chapter on creating BNRItem
import Cocoa
import Foundation
extension Character {
func unicodeIntValue() -> UInt32
{
let str = String(self)
return str.unicodeScalars[str.unicodeScalars.startIndex].value
}
@iamatypeofwalrus
iamatypeofwalrus / find_insert_index.rb
Last active August 29, 2015 14:04
Binary search a sorted array for the correct index in which to place a new value.
class Array
# find_insert_index -> returns the index that the value should be inserted into
# to keep the array sorted
# Arguments
# val -> any sort of value that supports comparison or...
# &block -> If you want to compare a specific field on your object you could:
# {|x,y| x.FIELD <=> y.FIELD }
# or you could sort reverse:
# {|x,y| y <=> x} NOTE: your review must be sorted desc. for this to work.
@iamatypeofwalrus
iamatypeofwalrus / run_single_files_or_test.md
Last active August 29, 2015 14:03
Running Singles Files/Tests in Rails the Easy Way

Just one type of test

ruby test/functional/person_controller.rb

Specific test

ruby test/functional/person_controller.rb -n test_that_will_run

Use some basic regexp

ruby test/functional/person_controller.rb -n /that_one_end_point_name/

Note

@iamatypeofwalrus
iamatypeofwalrus / add_milliseconds_to_mysql_and_activerecord_timestamps.md
Last active February 2, 2024 15:38
ActiveRecord: Store Milliseconds (or Microseconds) in Timestamps/Datetimes with Rails / MySQL

ActiveRecord: Store Milliseconds (or Microseconds) in Timestamps with Rails / MySQL

Milliseconds in your Timestamps.

We got 'em, you want 'em.

Why

Shit needs to be PRECISE

LICENSE

MIT

@iamatypeofwalrus
iamatypeofwalrus / stacktrace.md
Last active July 28, 2023 13:07
Print stacktrace without raising and Exception in Ruby and/or Rails

Print a stacktrace in Ruby or Rails without raising an exception

Why

You know what method is being and you want to figure out how it got there. Raising an exception is a bit harsh since all you want is a stack trace

How

puts caller

Seriously. It's that easy. If you're getting too much information you could

@iamatypeofwalrus
iamatypeofwalrus / application_switcher_fix.md
Last active July 16, 2018 20:28
Get Application Switcher (cmd + Tab) to show up in both displays in OS X Mavericks

Fix Cmd Tab / Application switcher in OS X10.9 Mavericks

What

OS X Mavericks has some some seriously awesome dual screen support (Mutha-Fuckin' finally, AMIRITE?) but there seems to be a bug if you have your docked pinned to either side of your display.

The Fix

Unfortunately, it means moving your dock :-(

Sad times my friends.

@iamatypeofwalrus
iamatypeofwalrus / bootstrap_glyphs_in_rails.md
Last active February 9, 2022 15:27
Get Glyphicons up and running in Rails 3.2 without using a gem

Getting Glyphicons from Bootstrap 3.0 in Rails: the easy way

What

Bootstrap 3.0 gives you access to the awesome icon set icon set by these dudes but it's not obvious for a Rails newbie like myself to get it all working together nicely

How

  1. Download the bootstrap-glyphicons.css from here. Save that file to RAILS_ROOT/vendor/assets/stylesheet/bootstrap-glyphicons.css
  2. Save all the font files in /dist/fonts from the Bootstrap 3.0 download to a new folder in your Rails app RAILS_ROOT/vendor/assets/fonts
  3. Add this folder to the asset pipeline by appending config.assets.paths << Rails.root.join("vendor","assets", "fonts") to application.rb after the line that has class Application < Rails::Application.
  4. In bootstrap-glyphicons.css modify the the `url
@iamatypeofwalrus
iamatypeofwalrus / Bootsrap 3.0_in_Rails.md
Last active February 9, 2022 15:27
Add Bootstrap to your Rails app without a Gem

Bootstrap 3.0 in Rails without a Gem

What is Bootstrap?

It's a collection of CSS styles and Javascript add-ons that stop your site from looking like a shitty craigslist rip off from 1996. Seriously, who wants that?

Docs: CSS, Components, Javascript

Why Install It This Way?

Finding the right gem, keeping it updated, and learning the syntax is a pain in the ass. Why not install Bootstrap the way you'd install new javascript libraries?

@iamatypeofwalrus
iamatypeofwalrus / tabCompleter.py
Created May 23, 2013 17:38
A simple Python Tab Completer for either system paths OR lists.
import os
import sys
import readline
import glob
class tabCompleter(object):
"""
A tab completer that can either complete from
the filesystem or from a list.