View ringbuffer.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
class RingBuffer < Array | |
attr_reader :max_size | |
def initialize(max_size, enum = nil) | |
@max_size = max_size | |
enum.each { |e| self << e } if enum | |
end | |
def <<(el) | |
if self.size < @max_size || @max_size.nil? |
View unicorn.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
root = "/var/www/cake/current" | |
working_directory root | |
pid "#{root}/tmp/pids/unicorn.pid" | |
stderr_path "#{root}/log/unicorn.stderr.log" | |
stdout_path "#{root}/log/unicorn.log" | |
listen "/tmp/unicorn.cake.sock" | |
worker_processes 2 | |
timeout 15 |
View gist:942131cc6795cbf98ceb
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
@media print { | |
.col-sm-1, .col-sm-2, .col-sm-3, .col-sm-4, .col-sm-5, .col-sm-6, .col-sm-7, .col-sm-8, .col-sm-9, .col-sm-10, .col-sm-11, .col-sm-12 { | |
float: left; | |
} | |
.col-sm-12 { | |
width: 100%; | |
} | |
.col-sm-11 { | |
width: 91.66666667%; | |
} |
View linebreak.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
require 'axlsx' | |
Axlsx::Package.new do |package| | |
workbook = package.workbook | |
workbook.add_worksheet do |sheet| | |
wrap = workbook.styles.add_style alignment: {wrap_text: true} | |
sheet.add_row ["Foo\r\nBar", "Foo\rBar", "Foo\nBar", "Foo\n\r\nBar"], style: wrap | |
end | |
package.serialize "linebreak.xlsx" |
View each_slice.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
Array.prototype.each_slice = function (size, callback){ | |
for (var i = 0, l = this.length; i < l; i += size){ | |
callback.call(this, this.slice(i, i + size)); | |
} | |
}; | |
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].each_slice(3, function (slice){ | |
console.log(slice); | |
}); |
View jquery.parseparams.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
// Add an URL parser to JQuery that returns an object | |
// This function is meant to be used with an URL like the window.location | |
// Use: $.parseParams('http://mysite.com/?var=string') or $.parseParams() to parse the window.location | |
// Simple variable: ?var=abc returns {var: "abc"} | |
// Simple object: ?var.length=2&var.scope=123 returns {var: {length: "2", scope: "123"}} | |
// Simple array: ?var[]=0&var[]=9 returns {var: ["0", "9"]} | |
// Array with index: ?var[0]=0&var[1]=9 returns {var: ["0", "9"]} | |
// Nested objects: ?my.var.is.here=5 returns {my: {var: {is: {here: "5"}}}} | |
// All together: ?var=a&my.var[]=b&my.cookie=no returns {var: "a", my: {var: ["b"], cookie: "no"}} | |
// You just cant have an object in an array, ?var[1].test=abc DOES NOT WORK |
View node-and-npm-in-30-seconds.sh
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
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc | |
. ~/.bashrc | |
mkdir ~/local | |
mkdir ~/node-latest-install | |
cd ~/node-latest-install | |
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 | |
./configure --prefix=~/local | |
make install # ok, fine, this step probably takes more than 30 seconds... | |
curl https://www.npmjs.org/install.sh | sh |
View coderwall.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
#!/usr/bin/env ruby | |
# Author : Emad Elsaid (https://github.com/blazeeboy) | |
require "selenium-webdriver" # gem install selenium-webdriver | |
require "highline/import" # gem install highline | |
def coderwall github_email, github_password, title, content, tags | |
driver = Selenium::WebDriver.for :firefox | |
driver.navigate.to "https://coderwall.com/auth/github" |
View mobile-uploader.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
#!/usr/bin/env ruby | |
# Author : Emad Elsaid (https://github.com/blazeeboy) | |
require 'sinatra' | |
set :port, 3000 | |
set :environment, :production | |
get '/' do | |
<<-EOT | |
<html><head> |
View maze.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
#!/usr/bin/env ruby | |
# Author : Emad Elsaid (https://github.com/blazeeboy) | |
require 'gosu' | |
include Gosu | |
DIMENSION, SPLITS, COLOR = 200, 50, Color::GREEN | |
# credits to: http://en.wikipedia.org/wiki/Maze_generation_algorithm | |
class GameWindow < Window | |
def initialize | |
super DIMENSION, DIMENSION, false, 1000 | |
self.caption = "Maze" |
NewerOlder