View generate_csv.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the easiest way to generate a csv and have it downloaded by the user. | |
# Drop this in a method in the controller and call it on click. | |
require 'csv' | |
file = CSV.generate do |csv| | |
csv << ["Name", "Email"] # headers | |
Contact.all.each do |person| | |
csv << [person.name, person.email] | |
end |
View New mac address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place this in your .bash_profile to change your mac address | |
# Simply run newmac from your terminal and boom, you'll have a new mac address | |
# Change mac address | |
function newmac() { | |
local OLDMAC=$(ifconfig en0 | grep ether | cut -d ' ' -f 2) | |
local GENMAC=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//') | |
sudo ifconfig en0 ether $GENMAC |
View gist:5177151
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias ls='ls -GFh' | |
export CLICOLOR=1 | |
# From Andrzej Szelachowski's ~/.bash_profile: | |
# Note that a variable may require special treatment | |
#+ if it will be exported. | |
DARKGRAY='\[\e[1;30m\]' |
View fizzbuzz.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a program that prints out the numbers 1 to 100 (inclusive). | |
# If the number is divisible by 3, print Fizz instead of the number. | |
# If it's divisible by 5, print Buzz. If it's divisible by both 3 and 5, print FizzBuzz. | |
# Final Version | |
puts (1..100).collect{ |i| (i % 3 == 0 && i % 5 == 0) ? "FizzBuzz" : (i % 5 == 0) ? "Buzz" : (i % 3 == 0) ? "Fizz" : i}.join("\n") | |
# Version 1 | |
1.upto(100) do |i| | |
if i % 3 == 0 && i % 5 == 0 |
View google-seo-scraper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a small program written in Node. I did NOT know anything about Node until coding this. | |
// The goal was to mimic this guy right here, without using a framework: https://github.com/carlsednaoui/google-allintitle-scraper | |
// You'll need a file named keywords.txt | |
// It will return a file names results.txt | |
var fs = require('fs'), | |
http = require('http'); | |
var query = "http://www.google.com/search?q=allintitle:", |
View number_to_the_n.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function calc(number, power, sum) { | |
return power === 0 ? sum : calc(number, --power, (sum || 1) * number ); | |
})(2, 10) | |
(function calculate(number, power, result, i) { | |
if (i === 10) { return; } | |
i++; | |
result = result * number; | |
console.log(result); |
View Evolution of a Ruby Programmer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Newbie Programmer | |
def factorial(x) | |
if x == 0 | |
return 1 | |
else | |
return x * factorial(x - 1) | |
end | |
end | |
puts factorial(6) | |
puts factorial(0) |
View count.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count = (function count() { | |
var counter = 0; | |
return function() { | |
return counter++; | |
} | |
})() |
View createElement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createElement(type, attrs) { | |
return Object.keys(attrs).reduce( | |
function(el, n) { el[n]=attrs[n]; return el; }, | |
document.createElement(type) | |
); | |
} | |
What does it do? Without jQuery, it elegantly creates an element with attributes. | |
createElement('a', { |
View simple_timer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $(document).ready(function() { | |
// var counter = timer(90); // time in seconds | |
// var status = "active"; | |
// function timer(count) { | |
// var intervalID = setInterval(function() { | |
// $('.timer').text(status + ": " + count); | |
// count -= 1; | |
// if (count <= 0 && status == "active") { |
OlderNewer