Skip to content

Instantly share code, notes, and snippets.

View stauntonknight's full-sized avatar

Vivek Agarwal stauntonknight

  • Bangalore, India
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
winston.loggers.add('application', {
console: {
level: 'silly',
colorize: true
},
file: {
level: 'info',
filename: path.join(__dirname, 'logs/tmp.log')
}
@stauntonknight
stauntonknight / NumZeroesInFactorial
Created April 20, 2012 21:06
Error saying "Can't assign double to variable of type int" on line 7
def num_zeroes_in_fact(n:int):int
count = 0
pow = 1
while (Math.pow(5,pow) <= n)
den = Math.pow(5,pow)
add = n/den
count = count + add
pow += 1
end
count
.rvm/gems/ruby-1.9.3-p125@ww/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
Command terminated
@stauntonknight
stauntonknight / email_validator.rb
Created August 28, 2011 19:56 — forked from scudco/email_validator.rb
Rails 3 Email Validator
class EmailValidator < ActiveModel::EachValidator
# http://fightingforalostcause.net/misc/2006/compare-email-regex.php
# Thanks to James Watts and Francisco Jose Martin Moreno
EMAIL_REGEX = /^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i
def validate_each(object,attribute,value)
if value.blank?
object.errors[attribute] << (options[:message] || "can't be blank") unless options[:allow_blank]
elsif !(value =~ EMAIL_REGEX)
object.errors[attribute] << (options[:message] || "is not a valid email address")