Skip to content

Instantly share code, notes, and snippets.

@iamatypeofwalrus
iamatypeofwalrus / roll_ipython_in_aws.md
Last active January 22, 2024 11:18
Create an iPython HTML Notebook on Amazon's AWS Free Tier from scratch.

What

Roll your own iPython Notebook server with Amazon Web Services (EC2) using their Free Tier.

What are we using? What do you need?

  • An active AWS account. First time sign-ups are eligible for the free tier for a year
  • One Micro Tier EC2 Instance
  • With AWS we will use the stock Ubuntu Server AMI and customize it.
  • Anaconda for Python.
  • Coffee/Beer/Time
@iamatypeofwalrus
iamatypeofwalrus / ssh_give_terminal_tabs_useful_names.md
Last active May 6, 2016 15:22
Customize SSH tab name in Mac OS X terminal auto-magically.

What

Automtically configure tab name in Terminal.app when ssh-ing to a server. You can use any shell commands you want to get the desired output.

Why

I work on external servers 8 hours a day M-F and more likely than not I have multiple ssh sessions at the same time to the same sever under different users. It became a bit of a pain to have to rename the tabs everytime I logged on to a server. I just wanted that to happen auto-magically.

I searched the interwebs and came across this CNet article which had about 99% of what I was looking for. However, it never really mentioned how to modify the script to insert your own formatting. It didn't even mention adding it to your $PATH! So after a few minutes of messing with it I got something quite reasonable. I thought I'd share the results.

How

@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.
@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 / 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 / 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 / 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 / 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 / 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 / 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.