Skip to content

Instantly share code, notes, and snippets.

View robvolk's full-sized avatar

Rob Volk robvolk

View GitHub Profile
@robvolk
robvolk / example.rb
Last active August 29, 2015 14:21
Perform Sidekiq jobs async on any queue!
class HackTheWorld
include Sidekiq::Worker
include Sidekiq::AnyQueue
def perform(arg1, arg2)
// ...
end
end
HackTheWorld.perform_async_on_queue(:fast, "arg1", "arg2")
@robvolk
robvolk / Preferences.sublime
Last active September 2, 2015 21:07
Sublime Text Developer Settings
{
"caret_extra_width": 1,
"caret_style": "phase",
"color_scheme": "Packages/Color Scheme - Default/SpaceCadet.tmTheme",
"ensure_newline_at_eof_on_save": true,
"fade_fold_buttons": false,
"font_size": 15,
"highlight_line": true,
"ignored_packages":
[
@robvolk
robvolk / application.js
Created August 15, 2013 22:02
AJAX Forms in Rails => Here are the basic components of building an automagic AJAX form with Ruby on Rails. Rails takes care of the plumbing of submitting the data for you, but leaves the UI logic entirely up to you. Just hook into the Rails' AJAX JavaScript events to control the UI logic.
// load Ruby on Rails unobtrusive scripting adapter for jQuery
// handles AJAX forms and client-side validation
//= require jquery_ujs
@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 / 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 / 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 / rails_console_reload.rb
Created January 12, 2017 19:40
Reload file in lib on Rails Console
load "#{Rails.root}/lib/my_file.rb"
" 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 / 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 / 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 + ': '"
}