Skip to content

Instantly share code, notes, and snippets.

View robvolk's full-sized avatar

Rob Volk robvolk

View GitHub Profile
@robvolk
robvolk / .bash_profile.sh
Created August 21, 2018 16:58
Cleanup git branches
gitc() {
git fetch --prune
for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`;
do
git branch -D $branch
done;
git branch --merged master | grep -v '^*' | grep -v '^ master$' | xargs git branch -d
}
" Rob Volk's .vimrc, completely based off of " This is Rob Volk's .vimrc, completely based off of Gary Bernhardt's .vimrc file
" vim:set ts=2 sts=2 sw=2 expandtab:
autocmd!
call pathogen#infect('bundle/{}')
call plug#begin('~/.vim/plugged')
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
@robvolk
robvolk / upgrade_vim.sh
Created August 9, 2017 15:27
Upgrade / Update Vim & all plugins
function upgrade-vim {
brew update
brew upgrade vim
cd ~/.vim/bundle
for i in `ls`; do
cd "$i"
git pull
cd ..
done
@robvolk
robvolk / slack_scrabble_emoji.sh
Created July 26, 2017 22:10
Slack Scrabble Emoji function in Bash
function scrabble {
node -p -e "const s = '$1'; let o = ''; for (c of s) o += ':scrabble-' + c + ': '"
}
@robvolk
robvolk / rails_console_reload.rb
Created January 12, 2017 19:40
Reload file in lib on Rails Console
load "#{Rails.root}/lib/my_file.rb"
@robvolk
robvolk / es6_fetch_example.js
Last active October 17, 2019 16:46
AJAX requests in ES6 using fetch()
// ES6 Fetch docs
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
fetch('https://some.url.com')
.then(response => {
if (response.ok) {
return Promise.resolve(response);
}
else {
return Promise.reject(new Error('Failed to load'));
@robvolk
robvolk / hash_has_values.js
Last active November 3, 2016 23:23
Determine if a hash has any of a set of values defined using sweet ES6 functional programming methods #map and #reduce
function hasValues(hash, fields) {
return fields.map(field => {
return hash[field] != null;
}).reduce((x, y) => { return x || y });
}
hash = { name: "robert paulson", affiliation: "fightclub" };
hasValues(hash, [ "name", "email" ]); // => true
hasValues(hash, [ "email" ]); // => false
@robvolk
robvolk / count_values_of_array.rb
Last active February 15, 2016 19:12
Count & sort values of a Ruby Array
food = ["bacon", "eggs", "cheese", "eggs", "bacon", "bacon", "bacon"]
food.inject(Hash.new(0)) {|h, k| h[k] += 1; h }.sort_by {|k,v| -1 * v}
# => [["bacon", 4], ["eggs", 2], ["cheese", 1]]
@robvolk
robvolk / enable_moped_logger.rb
Created August 18, 2015 17:14
See raw MongoDB queries from Mongoid / Moped by enabling Logger
# From Rails console, run the following and you'll see raw Moped queries for every Mongoid query!
Moped.logger = Logger.new(STDOUT)
@robvolk
robvolk / n_grams_code_challenge.md
Last active March 30, 2022 01:18
N-Grams Code Challenge

Foxbox Digital N-Grams Code Challenge

This is a small programming problem to test your technical ability and coding style.

Instructions

Write a simple script to generate a set of n-grams from a string of text. N-grams are a contiguous sequence of n words from a string of text, and have many applications from full-text search indexes to machine learning.

You'll generate a set of every permutation of contiguous n-grams from a string of text, from 1-gram to n-grams where n is the number of words in the string

Example