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
def average(*numbers) | |
((numbers.inject {|sum, element| sum + element}) / numbers.length).to_f | |
end |
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
<?php | |
require_once("bootstrap.php"); | |
/* | |
* | |
* The template class to handle the output to a template file. It's good | |
* because it seperates all the PHP code from the actual HTML, except for | |
* the PHP markup used to output the data. | |
* | |
* It's used by making a file in the root directory |
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
<?php | |
/* | |
* | |
* Simple template engine | |
* | |
*/ | |
class Template { | |
private $data; |
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
#include <stdio.h> | |
main() { | |
// String to contain program | |
char *program = "#include <stdio.h>%cmain() {%c char *program = %c%s%c;%c printf(program, 10, 10, 34, program, 34, 10, 10, 10);%c}%c"; | |
/* Insert ascii characters for colon and newline | |
Write out the program, two new lines, at 34 we start colons | |
at the program pointer, in the colons write out the program | |
_again_ stop colons, and paste out some new lines, done! */ | |
printf(program, 10, 10, 34, program, 34, 10, 10, 10); | |
} |
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
#! /bin/bash | |
WINTITLE="sakura" # Name of the window (or part of it) | |
PROGRAMNAME="sakura" # Name of the program, so it can be opened if there's no window currently | |
# Lists all windows, if there's one containing $WINTITLE it'll return 1, and bring the current instance of the program to the front. | |
if [ `wmctrl -l | grep -c "$WINTITLE"` != 0 ] | |
then | |
wmctrl -a "$WINTITLE" | |
# Else, it'll launch a new instance | |
else |
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
# Implementation of TheLinx's BrainDamage in Ruby | |
# => http://gist.github.com/402454 | |
# | |
class BrainDamage < Array | |
SPACE = 32 | |
NEWLINE = 10 | |
def run(file) | |
file = get_file_content(file) |
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
# not so insane | |
class Fixnum | |
def fizzbuzz | |
buffer = '' | |
buffer += 'Fizz' if self % 3 == 0 | |
buffer += 'Buzz' if self % 5 == 0 | |
buffer.empty? ? self : buffer | |
end | |
end |
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 'benchmark' | |
require 'redis' | |
require 'yaml' | |
require 'json' | |
N = 100000 | |
Benchmark.bm do |r| | |
@redis = Redis.new | |
@serialize_me = [1,2,3,4,5] |
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 | |
puts "8#{'='*STDIN.read[/\d/].to_i}D" | |
# $ uptime | |
# 23:42 up 56 days, 15:19, 2 users, load averages: 0.34 0.41 0.41 | |
# $ uptime | ruby epenis.rb | |
# 8========================================================D |
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
if defined? ActiveRecord | |
def explain(query) | |
query = query.to_sql if query.is_a?(ActiveRecord::Relation) | |
ActiveRecord::Base.connection | |
.execute("EXPLAIN ANALYZE #{query}") | |
.to_a | |
.each { |hash| puts hash["QUERY PLAN"] } | |
nil |