Skip to content

Instantly share code, notes, and snippets.

View BideoWego's full-sized avatar
:octocat:
Yarp

Chris Scavello BideoWego

:octocat:
Yarp
View GitHub Profile
@BideoWego
BideoWego / set_generator.rb
Created August 29, 2015 07:57
Generates an exhaustive set of number combinations consisting of `e` positions in each combination and each number in the combination is a value 0 to `n`
# Generates an exhaustive set of number combinations
# consisting of `e` positions in each combination
# and each number in the combination is a value 0 to `n`
#
# - examples:
# set(2, 2)
# => [[0, 0], [0, 1], [1, 0], [1, 1]]
#
# set(3, 3)
# => [[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 2, 0], [0, 2, 1], [0, 2, 2], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2, 0], [1, 2, 1], [1, 2, 2], [2, 0, 0], [2, 0, 1], [2, 0, 2], [2, 1, 0], [2, 1, 1], [2, 1, 2], [2, 2, 0], [2, 2, 1], [2, 2, 2]]
@BideoWego
BideoWego / index.rb
Last active November 26, 2015 18:32
Create all the combinations of 0 to n with e positions
# Array.new(2**5) do |i|
# [i / 2**4, i / 2**3 % 2, i / 2**2 % 2, i / 2 % 2, i % 2]
# end
# integer_combinations(2, 5)
# => [[0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 1, 0], [0, 0, 0, 1, 1], [0, 0, 1, 0, 0], [0, 0, 1, 0, 1], [0, 0, 1, 1, 0], [0, 0, 1, 1, 1], [0, 1, 0, 0, 0], [0, 1, 0, 0, 1], [0, 1, 0, 1, 0], [0, 1, 0, 1, 1], [0, 1, 1, 0, 0], [0, 1, 1, 0, 1], [0, 1, 1, 1, 0], [0, 1, 1, 1, 1], [1, 0, 0, 0, 0], [1, 0, 0, 0, 1], [1, 0, 0, 1, 0], [1, 0, 0, 1, 1], [1, 0, 1, 0, 0], [1, 0, 1, 0, 1], [1, 0, 1, 1, 0], [1, 0, 1, 1, 1], [1, 1, 0, 0, 0], [1, 1, 0, 0, 1], [1, 1, 0, 1, 0], [1, 1, 0, 1, 1], [1, 1, 1, 0, 0], [1, 1, 1, 0, 1], [1, 1, 1, 1, 0], [1, 1, 1, 1, 1]]
def integer_combinations_of(n, e)
Array.new(n**e) do |i|
@BideoWego
BideoWego / index.sql
Created November 26, 2015 18:41
Time Series Data SQL Example in PostgreSQL
-- ------------------------------------------------
-- Weekly
-- ------------------------------------------------
-- Revenue for week range
SELECT
DATE(weeks) AS week,
COALESCE(SUM(order_contents.quantity * products.price), 0) AS amount
FROM GENERATE_SERIES(
DATE_TRUNC('WEEK', DATE('2015-9-1')),
@BideoWego
BideoWego / adapter_acknowledeable.rb
Last active December 9, 2015 20:31
A Ruby on Rails model concern that allows a model to reference the database adapter type via a simple getter, great for database driver specific functionality!
module AdapterAcknowledgeable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def adapter
self.connection.instance_values["config"][:adapter]
end
end
@BideoWego
BideoWego / _flash.html.erb
Last active February 15, 2016 05:54
Rails flash partial with Bootstrap classes
<% unless flash.empty? %>
<% flash.each do |key, value| %>
<div class="main-flash alert alert-<%= flash_css_class(key) %> text-center" style="border-radius: 0;">
<%= value %>
</div>
<% end %>
<% end %>
@BideoWego
BideoWego / Key Bindings - User
Last active February 17, 2016 19:39
My Sublime Text 3 Preferences
[
{ "keys": ["super+shift+w"], "command": "close_all" }
]
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
@BideoWego
BideoWego / folder.js
Created March 23, 2016 04:36
Small jQuery plugin to fold nested divs
// ----------------------------------------
// Folder jQuery plugin
// ----------------------------------------
// Usage:
//
// $('.folder.month').folder();
// $('.folder.year').folder({
// iconOpen: 'fa-folder-open',
// iconClosed: 'fa-folder'
// });
@BideoWego
BideoWego / JavaScript-Dos-and-Donts.js
Last active March 24, 2016 00:38
A list of JavaScript gotchas and best practices mostly dealing with the MVC and Module pattern
// --------------------------------------------------
// JavaScript Do's and Dont's
// --------------------------------------------------
//
// This is a list of gotchas and best practices
// mostly dealing with the MVC and Module pattern
//
@BideoWego
BideoWego / Pro.terminal.xml
Last active March 28, 2016 20:14
My Terminal Profile Preferences
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackgroundBlur</key>
<real>0.0</real>
<key>BackgroundColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OV05TV2hpdGVcTlNDb2xvclNwYWNlViRjbGFzc00w