Skip to content

Instantly share code, notes, and snippets.

@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 / channel_check.go
Created December 11, 2014 19:31
Check if a Go Channel is open or closed
// An intersting pattern for testing, but you can use the check anywhere
import "testing"
func TestCheckingChannel(t *testing.T) {
stop := make(chan bool)
// Testing some fucntion that SHOULD close the channel
func (stop chan bool) {
close(chan)
}(stop)
@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 / 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 / README.md
Last active March 30, 2023 20:54
A Rails 4 pluck in batches implementation

pluck_in_batches

Sometimes you need to iterate over a ton of items and you don't want the overhead of creating AR objects out of all of them. Hell, you only need a few things! Well, #pluck has your back.

But what if you want to iterate over many tonnes of items?

Pluck in batches to the rescue!

This isn't the exact code that I use in my code base, but it is damn close.

@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 / 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 / generate_ctags.md
Last active February 11, 2019 10:17
Generate ctags for Atom (or for any other reason) on Mac os X

Why?

Atom can automagically picks up any tags file in your current directory which enables you to:

  • shift+cmd+r search for any function in your project
  • alt+cmd+down GoTo a function declaration

How

Get brew if you don't already have it. Then:

brew install ctags

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