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 / Font Awesome 4.3.0
Last active September 22, 2019 23:50
A full list of Font Awesome 4.3.0 css classes, html entities and css character codes separated 1 space for easy formatting into an array or hash
fa-adjust  \f042
fa-adn  \f170
fa-align-center  \f037
fa-align-justify  \f039
fa-align-left  \f036
fa-align-right  \f038
fa-ambulance  \f0f9
fa-anchor  \f13d
fa-android  \f17b
fa-angellist  \f209
@BideoWego
BideoWego / model.py
Last active December 16, 2019 16:55
Simple Python Model class for use with SQLite3
import sqlite3
class Model:
def __init__(self, db, table):
self.db = db
self.table = table
self.connection = sqlite3.connect(db + '.db')
self.connection.row_factory = sqlite3.Row
def create(self, row):
@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 / _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 / _errors.html.erb
Last active November 28, 2017 11:14
Rails helper to get validation error messages for a given object or an optional field on that object. Also a view partial to output those errors.
<% if object.errors.present? %>
<div class="alert alert-danger">
<%
field ||= nil
error_messages_for(object, field) do |error|
%>
<%= error %>
<br/>
<% end %>
</div>
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 / a_rails_rspec_checklist\README.md
Last active January 13, 2022 12:20
Rails Spec setup checklist, helper and support files

Rails RSpec Checklist

  • Ensure turbolinks is disabled for good measure

    • comment out gem
    • remove from javascript asset pipeline
    • remove from application layout
  • Add the following gems to Gemfile in a development, test group

    • hirb
@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