Skip to content

Instantly share code, notes, and snippets.

🤷‍♀
Probably absolutely.

Tim Uruski timuruski

🤷‍♀
Probably absolutely.
Block or report user

Report or block timuruski

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
@timuruski
timuruski / 10_rubocop.sh
Last active Apr 24, 2018
Modular pre-commit hook, script.
View 10_rubocop.sh
#!/bin/bash --login
# Select only staged Ruby files, this may be expanded to other file types if necessary.
FILES="$(git diff --cached --name-only --diff-filter=AMC | grep -E "\.(erb|rake|rb)$" | tr '\n' ' ')"
# Check for ruby style errors
if [ -n "$FILES" ]; then
bundle exec rubocop --force-exclusion --format=simple ${FILES}
fi
@timuruski
timuruski / .gitconfig
Last active Mar 23, 2017
Git Fuzzy/Interactive Checkout
View .gitconfig
[alias]
ci = "!source ~/.githelpers && fuzzy_checkout"
@timuruski
timuruski / delta_t.rb
Created Jan 20, 2017
Script for dumping the time difference between a bunch of log lines.
View delta_t.rb
#!/usr/bin/env ruby
require 'time'
# USAGE: This takes a bunch of lines as input, looks for dates, sorts them and
# then outputs the difference between the smallest and largest.
#
# pbpaste | ruby delta-t
# tail -f log/development.log | ruby delta-t
#
# TODO:
@timuruski
timuruski / query_cache_example.rb
Created Jan 19, 2017
Two possible ways to implement a basic in-memory cache for DB queries. One is more idiomatic, but I wonder if it's too idiomatic.
View query_cache_example.rb
class UserImporter < ImporterBase
def import_user
user_name = @data[:user_name]
# Which is easier to understand?
users_by_name[user_name]
# -- OR --
find_user_by_name(user_name)
end
@timuruski
timuruski / README.md
Created Dec 2, 2016
Greeter script structure example
View README.md

Structure of Ruby Scripts

This is an example of how to structure one-off Ruby scripts for easy growth, without making a big mess.

For more details on this, you can read my blog post about the idea or Confident Ruby by Avdi Grimm

View git-fetch-all
#! /bin/bash
set -e
bold=$(tput bold)
normal=$(tput sgr0)
WORKSPACE="${HOME}/workspace"
PROJECTS=(
dotfiles
@timuruski
timuruski / foo.rb
Created Mar 4, 2016
Ruby is weird sometimes
View foo.rb
class Foo
end
def Foo
Foo.new
end
p Foo.class
p Foo.new.class
p Foo().class
View box.sh
echo "\u250C\u2500\u252c\u2500\u2510\n\u251C\u2500\u253C\u2500\u2524\n\u2514\u2500\u2534\u2500\u2518"
View tanks_for_all_the_fish.rb
class TanksForAllTheFish < RTanque::Bot::Brain
NAME = 'Tanks For All the Fish'
MAX_RANGE = 400.0
include RTanque::Bot::BrainHelper
def tick!
if targets_nearby?
command.speed = 2.0
command.heading = Random.rand(-1.0..1.0)
@timuruski
timuruski / vimrc
Created Jul 16, 2015
Vim RunCmd primer
View vimrc
" Usage: To execute a Ruby file with some library included
" :RunCmd ruby -i lib/my_lib
" Then you can run your script by pressing <leader>r
command! -nargs=1 RunCmd nnoremap <leader>r :w \| !clear; <args> % <CR>
You can’t perform that action at this time.