Skip to content

Instantly share code, notes, and snippets.

Tyler Montgomery ubermajestix

Block or report user

Report or block ubermajestix

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ubermajestix
ubermajestix / slack_gif_shrinker.sh
Created Apr 23, 2016
Imagemagick Commands to shrink gif dimensions and file size to fit Slack's emoji policy (128x128 and 64k max)
View slack_gif_shrinker.sh
# Recommended in docs to build a new gif from the source
for f in *.gif; do convert "$f" -coalesce ${f%gif}coal.gif; done
# Resize to 128x128. All images were the same size
for f in *.coal.gif; do convert -size 512x512 "$f" -resize 128x128 ${f%gif}small.gif; done
# This worked pretty well to get most of these gifs under 64k to upload to Slack
for f in *.small.gif; do convert "$f" -colors 32 -dither none -deconstruct -layers optimize ${f%small.gif}opt.gif; done
@ubermajestix
ubermajestix / killport
Created Sep 10, 2015
Finds and kills a process on a port using lsof (only tested on OSX)
View killport
#!/usr/bin/env bash
# Kills a process running on a given port
#
# Examples:
# A process is running on port 3000, but we're not sure we want to kill it yet:
#
# $ killport 3000
# > Found pid 27448 running on 3000
# > tyler.montgomery 27851 0.0 0.0 2441988 684 s014 S+ 3:54PM 0:00.00 grep 27448 tyler.montgomery 27448 0.0 1.4 2727220 227784 s009 S+ 3:53PM 0:08.22 puma [app] init ...
@ubermajestix
ubermajestix / ruby_tip_of_the_week.rb
Last active May 22, 2018
Use Virtus to handle parsing data coming back from an API into easy to work with objects.
View ruby_tip_of_the_week.rb
# Sick of using Hashes or Hashie::Mash objects when working with API responses?
# Yeah, me too.
# Let's use Virtus to make some nice objects that work like we'd expect.
# For more checkout: https://github.com/solnic/virtus
# Given we get some JSON back from an API like this
{things: [
{name: 'Thing 1', created_at: '2014-09-11 15:57:33 -0700'},
{name: 'Thing 2', created_at: '2014-09-11 15:57:33 -0700'}
]
View refresh.vim
" ctags, ctrlp, NERDTree refresh
function Refresh()
echo "refreshing tags and files..."
silent !if [ -d .git ]; then git ls-files -c -o --exclude-standard | ctags -L -; else ctags -R; fi
if exists(":CtrlPClearAllCaches") == 2
CtrlPClearAllCaches
endif
@ubermajestix
ubermajestix / vpnconnect
Created Dec 9, 2013
This script allows you to open your vpn connection by launching an application. I use it to connect to a vpn from Alfred (you could use Quicksilver or LaunchBar too). In Automator, search for the "Run AppleScript" action. Double click it and copy and paste the code below. Change your vpn's name on line 3. Then export to your Applications folder …
View vpnconnect
tell application "System Events"
tell current location of network preferences
set VPNservice to service "yourVPN"
if exists VPNservice then set isConnected to connected of current configuration of VPNservice
if isConnected is false then
connect VPNservice
else
disconnect VPNservice
end if
end tell
@ubermajestix
ubermajestix / README.md
Last active Dec 27, 2015
Twitter Interview Question
View README.md

This code visualizes the solution to this Twitter interview question.

My first solution only looked at immediate neighbors to figure out if you're in a trough that will collection water. The clever part is considering all values to the left and right of you, not immediate neighbors. My naive solution to [5,1,5] was pretty close, but as I expanded to more complex problems, considering your neighbors wasn't enough and my solution began to bloat. Looking at this answer gave me the insight to strip down my solution.

Once I had it solved I went back and built the simple solution display.

To run the tests simply run $> ruby -Itest rain_test.rb

View giftube.rb
#! /usr/bin/env ruby
require 'rubygems'
require 'main'
require 'pathname'
require 'fileutils'
Main{
argument("youtube_url")
View Tcomment_Bindings.vim
" Use tcomment instead of Nerd_commenter
if has("gui_macvim") && has("gui_running")
inoremap <D-/> <Esc>:TComment<CR>i
nnoremap <D-/> :TComment<CR>
vnoremap <D-/> :TComment<CR>
else
inoremap <leader>/ <Esc>:TComment<CR>i
nnoremap <leader>/ :TComment<CR>
vnoremap <leader>/ :TComment<CR>
endif
@ubermajestix
ubermajestix / git-open
Last active Dec 12, 2015
A git command to open remotes and branches in a browser
View git-open
#! /usr/bin/env ruby
# If the remote repository is hosted on GitHub.com (or GitHub Enterprise) this
# git command will allow you to open your browser to the specified branch on a
# given remote.
#
# For example:
# Given the remote:
# origin git@github.com:ubermajestix/some_app.git
#
# Running:
@ubermajestix
ubermajestix / inspector.rb
Created Sep 5, 2012
Override inspect on ruby objects
View inspector.rb
# When an RSpec test like this fails,
#
# @my_array.should == [@some_model, @some_model2]
#
# RSpec will call inspect on each of the objects to "help" you figure out
# what went wrong. Well, inspect will usually dump a TON OF SHIT and make trying
# to figure out why `@my_array` is not made up of `@some_model` and `@some_model2`.
#
# This little module and technique helps get around that. It will redefine `inspect`
# if you include it in your model object.
You can’t perform that action at this time.