Skip to content

Instantly share code, notes, and snippets.

View carlsednaoui's full-sized avatar

Carl Sednaoui carlsednaoui

View GitHub Profile
@carlsednaoui
carlsednaoui / vertical-align.css
Created February 1, 2014 05:58
CSS - Vertical Align
/*http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/*/
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
@carlsednaoui
carlsednaoui / optimizely.js
Created March 5, 2014 22:53
Optimizely for Angular
window.myInterval = setInterval(function() {
if ($(SELECTOR).length > 0) {
OPTIMIZELY CHANGES
clearInterval(window.myInterval);
}
}, 50);
@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
@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 / scrape-cio.js
Created November 9, 2015 15:53
Get stats from Customer.io
// Create result object, where everything will get saved
var result = '';
// create the headers
result += 'campaign name, status, created, updated, failed, sent, opened, clicked, converted';
result += '\n';
// loop over each row
$('tbody tr').each(function(i, el) {
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 / 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
@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);
# 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 / count.js
Created April 15, 2013 01:35
My first closure! :)
var count = (function count() {
var counter = 0;
return function() {
return counter++;
}
})()