Skip to content

Instantly share code, notes, and snippets.

@sgrshah
sgrshah / dnsmasq OS X.md
Created October 10, 2023 14:54 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

To setup your computer to work with *.test domains, e.g. project.test, awesome.test and so on, without having to add to your hosts file each time.

Requirements

Install

@sgrshah
sgrshah / recipes-form.rb
Created July 9, 2013 19:54
recipe form
<h1>Create a new recipe</h1>
<%= form_tag '/recipes' do%>
<%=label_tag 'recipe[name]', 'Enter Recipe:'%>
<label for="recipe[name]">Enter Recipe:</label>
<%=text_field_tag 'recipe[name]'%><br>
<input name="recipe[name]">
<%=label_tag 'recipe[ingredients_to_add][]', 'Enter Ingredient:'%>
<%=text_field_tag 'recipe[ingredients_to_add][]'%><br>
@sgrshah
sgrshah / word-reverse.rb
Created June 17, 2013 22:28
Word Reverse - Sagar
# From [Rubeque](http://rubeque.com/problems/reverse-each-word)
# Write a method that takes a sentence and returns it with each word reversed in place.
# ruby
# reverse_each_word.rb
# Write a method that takes a sentence and returns it with each word reversed in place.
# A String has many methods that can be called on it:
# http://www.ruby-doc.org/core-1.9.3/String.html
@sgrshah
sgrshah / jukebox-oo.rb
Created June 17, 2013 14:19
Jukebox refactor - Sagar
songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted",
"The Phoenix - Consolation Prizes"
]
class Song
@sgrshah
sgrshah / prime.rb
Created June 14, 2013 17:35
Prime number - Sagar
def check_prime(number)
check_max = (2..number-1)
if (check_max.all? {|divisor| number % divisor != 0})
puts "This number is prime"
else
puts "This number is not prime"
end
end
check_prime(5)
@sgrshah
sgrshah / hashketball.rb
Created June 11, 2013 13:47
Hashketball, Sagar Shah
game = {
:team_1 => {:name => "Knicks",
:colors => ["Blue", "Orange"],
:players => {
:player_1=> {
:name => "Amar'e Stoudemire",
:number => 5,
:shoe_size => 12,
:stats => {
:points => 20,
@sgrshah
sgrshah / tempbot.rb
Created June 10, 2013 21:45
Temperature bot, Sagar
def temperature_bot(temp)
case temp
when 18..21
"I like this temperature"
else
"This is uncomfortable for me"
end
end
@sgrshah
sgrshah / method_chaining.rb
Created June 10, 2013 21:42
Method Chaining, Sagar Shah
my_array = ["j","e","t","s","g","i","a","n","t","s"]
puts my_array.slice(0,4).join.prepend('j.e.t.s.').gsub("j", "J")
@sgrshah
sgrshah / make-hashes.rb
Created June 10, 2013 21:09
make-hashes, Sagar Shah
movies = {
:comedy => [
"Wedding Crashers",
"Superbad",
"Anchorman"
]
:action => [
"Bourne Ultimatum",
"Skyfall",
"Mission Impossible"
@sgrshah
sgrshah / simple-arrays.rb
Created June 10, 2013 20:02
simple arrays, sagar
# 1. Construct an array with your favorite foods. It should have at least 5 elements
favorite_foods = ["pav bhaji", "pizza", "falafel", "burrito", "egg & cheese"]
# Write a puts which returns your most favorite food out of the array.
puts favorite_foods[0]
# Construct an array with the colors of the rainbow (ROYGBIV)
rainbow_array = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
# Slice the colors Red, Orange, and Yellow out of the array.