Skip to content

Instantly share code, notes, and snippets.

@alfielapeter
alfielapeter / angular_currency_filter.js
Created May 7, 2013 17:40
Angular.js and Accounting.js Currency Filter
// sample use {{ value | currency:"USD" }}
angular.module('filters', []).filter('currency', function() {
return function(number, currencyCode) {
var currency = {
USD: "$",
GBP: "£",
AUD: "$",
EUR: "€",
CAD: "$",
MIXED: "~"
# This assumes that EVERY spec file has AT LEAST ONE SPEC in it. It can be pending but it must exist.
# Otherwise, the file_names and times will be off.
RSpec.configure do |config|
config.add_setting :file_count, default: 0
config.add_setting :file_times, default: {}
config.before(:all) do
@start = Time.now
end
@alfielapeter
alfielapeter / fizzbuzz.rb
Created March 3, 2011 18:26
basic fizzbuzz in ruby
for n in 1..100
if n.remainder(3) == 0 && n.remainder(5) == 0
puts "fizzbuzz"
elsif n.remainder(3) == 0
puts "fizz"
elsif n.remainder(5) == 0
puts "buzz"
else
puts n
end
@alfielapeter
alfielapeter / res_search.rb
Created January 13, 2011 20:08
Search model for a multiple database real estate search.
=begin
there are probably better ways to do this now and I wrote this when I was originally learning ror,
but it is a sample of something mildly complex that I wrote.
=end
class ResSearch < ActiveRecord::Base
belongs_to :users
has_many :search_alerts, :dependent => :destroy
include ApplicationHelper
# return a sanitized version of the image filename
# (remove spaces, etc.) and then determine position
# based on filename (eg. 1.jpg, 2.jpg)
def sanitize_and_position_photo
filename = self.image_file_name
ext = File.extname(filename)
just_filename = File.basename(filename, ext)
unless just_filename.to_i == 0
self.position = just_filename.to_i