Skip to content

Instantly share code, notes, and snippets.

View carlsednaoui's full-sized avatar

Carl Sednaoui carlsednaoui

View GitHub Profile
@carlsednaoui
carlsednaoui / count.js
Created April 15, 2013 01:35
My first closure! :)
var count = (function count() {
var counter = 0;
return function() {
return counter++;
}
})()
# Newbie Programmer
def factorial(x)
if x == 0
return 1
else
return x * factorial(x - 1)
end
end
puts factorial(6)
puts factorial(0)
@carlsednaoui
carlsednaoui / number_to_the_n.js
Last active December 15, 2015 06:39
Exponential calculation in JS
(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);
@carlsednaoui
carlsednaoui / google-seo-scraper.js
Last active February 22, 2020 17:50
Google All In Title Scraper
// 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:",
@carlsednaoui
carlsednaoui / fizzbuzz.rb
Last active December 15, 2015 02:09
Example of FizzBuzz
# 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
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\]'
@carlsednaoui
carlsednaoui / New mac address
Created August 29, 2012 02:56
Generate and set a new mac address
# 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
@carlsednaoui
carlsednaoui / generate_csv.rb
Last active October 6, 2015 12:17 — forked from jescalan/sample.rb
Easily generate a csv file.
# 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