Skip to content

Instantly share code, notes, and snippets.

View DiegoSalazar's full-sized avatar

Diego E. Salazar DiegoSalazar

View GitHub Profile
@DiegoSalazar
DiegoSalazar / prompt_func
Created December 5, 2011 16:22
terminal bash prompt
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
@DiegoSalazar
DiegoSalazar / gist:1726679
Created February 3, 2012 00:17
pre-commit hook to alert if a certain string found in code
#!/bin/sh
RED="\033[0;31m"
WHITE="\033[1;37m"
if git diff-index -p -M --cached HEAD | grep '#debug' > /dev/null; then
#echo 'debug lines found in commit. Aborting' >&2
#exit 1
echo "\n\t${RED}You left a debug comment in the code!${WHITE}\n" >&2
fi
attachments: parent_id, asset_id
domain_names: organisation_id
event_memberships: user_id, event_id
events: editor_id
group_actions: user_id, group_id
groups: user_id
icons: parent_id
invitations: sender_id
legacy_actions: item_upon_id
news_items: author_id
named_scope :with_over_lapping_dates, lambda {|starting_date, ending_date| {:conditions => ["? BETWEEN `start_date` AND `end_date` OR ? BETWEEN `start_date` AND `end_date`", starting_date, ending_date]}}
@DiegoSalazar
DiegoSalazar / order_spoof_finder.rb
Created September 13, 2012 18:15
Order spoof finder
class DasSpoofenSpleiza
def initialize(product_id)
@product = Product.find product_id, :include => :variants
end
def filter
start = Time.now
puts "\nGetting all order_items for product #{@product.id}..."
order_items = OrderItem.all({
:joins => [:order],
@DiegoSalazar
DiegoSalazar / validate_credit_card.js
Last active February 12, 2024 05:09
Luhn algorithm in Javascript. Check valid credit card numbers
// Takes a credit card string value and returns true on valid number
function valid_credit_card(value) {
// Accept only digits, dashes or spaces
if (/[^0-9-\s]+/.test(value)) return false;
// The Luhn Algorithm. It's so pretty.
let nCheck = 0, bEven = false;
value = value.replace(/\D/g, "");
for (var n = value.length - 1; n >= 0; n--) {
# A program that takes any single number (max) and returns all the numbers below (max) that is an exact square
def exact_squares(max)
s = []
while max > 0
s << max if is_exact_square? max
max -= 1
end
# A program that takes any single number (max) and returns all the numbers below (max) that are divisible by five or two but not by both five and two.
def mini_fizzbuzz(max)
s = []
max.downto 0 do |i|
s << i if (i % 2 == 0 || i % 5 == 0) && !(i % 2 == 0 && i % 5 == 0)
end
s
end
@DiegoSalazar
DiegoSalazar / .bash_profile
Created October 9, 2013 19:23
bashprofile prompt with git branch
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
@DiegoSalazar
DiegoSalazar / select_has_many_through.rb
Last active December 28, 2015 10:59
Using a drop down to add a relationship between has_many :through models.
# models
class Genotype < ActiveRecord::Base
has_many :genotypes_colors
has_many :colors, through: :genotypes_colors
# to post nested attributes in a form using fields_for
accepts_nested_attributes_for :genotypes_colors
# if you're using Rails 3 attr_accessible
attr_accessible :genotypes_colors_attributes, ...rest of accessible attribs