Skip to content

Instantly share code, notes, and snippets.

View aarti's full-sized avatar
🎯
Focusing

aarti

🎯
Focusing
  • San Francisco Bay Area
View GitHub Profile
@aarti
aarti / project_euler_problem1.rb
Last active December 15, 2015 18:59
Find the sum of all the multiples of 3 or 5 below 1000.
total= (1..999).reduce(0) do |sum,n|
n%3 == 0 || n%5 == 0 ? sum + n : sum
end
puts total
@aarti
aarti / coercing_closures.rb
Created November 1, 2013 21:51
Symbol#to_proc example
#http://pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html
#http://ruby-doc.org/core-2.0.0/Symbol.html#method-i-to_proc
2.0.0p247 :001 > a = ["first", "second", "third"]
=> ["first", "second", "third"]
2.0.0p247 :002 > a.collect(&:upcase)
=> ["FIRST", "SECOND", "THIRD"]
2.0.0p247 :003 > a.collect{ |n| n.upcase }
=> ["FIRST", "SECOND", "THIRD"]
2.0.0p247 :004 >
@aarti
aarti / mapping_data.rb
Created November 1, 2013 22:07
Mapping Data
def self.parse_detail( rows )
details = rows.map do |row|
detail = {}
[
[:line_item, 0],
[:title, 1],
[:asin, 2],
[:units_sold, 3],
[:units_refunded, 4],
[:net_units_sold, 5],
a = %q{ Hello World!
A lovely day in Santa Clara on April 21st
}
b = %Q{ #{a}
And the sun is shining
}
puts a
puts b
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
#!/bin/bash
#
# PostgreSQL Backup Script Ver 1.0
# http://autopgsqlbackup.frozenpc.net
# Copyright (c) 2005 Aaron Axelsen <[email protected]>
#
# This script is based of the AutoMySQLBackup Script Ver 2.2
# It can be found at http://sourceforge.net/projects/automysqlbackup/
#
# The PostgreSQL changes are based on a patch agaisnt AutoMySQLBackup 1.9
@aarti
aarti / tiny_str_in_big_str.rb
Created December 19, 2013 20:45
Different ways to to find a string in another string
string = "HOPJYJKCONNECTICUTQZIDAHOKR"
states = ["TEXAS", "ALASKA", "IDAHO", "FLORIDA", "MONTANA", "OHIO", "NEWMEXICO", "CONNECTICUT", "COLORADO"]
states.select { |s| string[s] }
states.select { |s| string.match s }
states.select { |s| string.include? s }
# => ["IDAHO", "CONNECTICUT"]
@aarti
aarti / alphagram.rb
Created December 26, 2013 05:33
Alphagram: An alphagram of a word (or of any group of letters) consists of the word's letters arranged in alphabetical order
irb(main):016:0> a = "aartiparikh"
=> "aartiparikh"
irb(main):022:0> a.split("").sort.join("")
=> "aaahiikprrt"
@aarti
aarti / hash_sort_functionally.rb
Last active January 2, 2016 00:49
Sort hash simply and functionally
db = { 7 => ["parikh", "shah"], 5 => ["sinha", "kaur"], 3 => ["sharma", "khan"]}
def sort_functional(db)
db.keys.sort.reduce({}) { |hash,item| hash.merge( item => db[item].sort ) }
end
def sort_simple(db)
sorted = {}
db.keys.sort.each do |n|
sorted[n]=db[n].sort
@aarti
aarti / jenkins_git_depot
Created January 4, 2014 20:21
Create a bare git depot, add it as remote then push to it. Useful when setting up jenkins locally.
mkdir -p ~/depot
git clone --bare ~/dev/aarti/myproject ~/depot/myproject.git
cd ~/dev/aarti/myproject
git remote add origin ~/dev/aarti/myproject
git remote -v
git push jenkins master