This file contains hidden or 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/ruby | |
class Lexer | |
def initialize(str) | |
@str = str | |
@p = 0 | |
end | |
def next_token | |
while true |
This file contains hidden or 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
module QueryCount | |
Max = 10 | |
module MysqlAdapterExtensions | |
def self.included(base) | |
base.alias_method_chain :execute, :review | |
end | |
def execute_with_review(sql, *args) | |
if Thread.current[:query_count] && ['select', 'insert', 'update', 'delete'].include?(sql[0 .. 6].downcase.strip) |
This file contains hidden or 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
$current = {:path => "*ROOT*", :children => [], :mem => 2 ** 30} | |
if GC.respond_to?(:enable_stats) | |
module RequireTracking | |
def require(*args) | |
node = {:path => args, :children => []} | |
$current[:children] << node | |
prev, $current = $current, node | |
start_allocated_size = GC.allocated_size |
This file contains hidden or 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
<? | |
// Why do we need the nodes? | |
//$nodes = json_decode('[{"x":3,"y":6,"id":0},{"x":1,"y":1,"id":1},{"x":3,"y":1,"id":2},{"x":3,"y":4,"id":3},{"x":5,"y":1,"id":4},{"x":6,"y":1,"id":5},{"x":4,"y":3,"id":6},{"x":1,"y":6,"id":7},{"x":4,"y":6,"id":8},{"x":6,"y":6,"id":9},{"x":3,"y":9,"id":10},{"x":6,"y":11,"id":11}]'); | |
$paths = json_decode('[[0,1],[0,2],[0,3],[3,2],[3,6],[6,4],[6,5],[3,9],[9,9],[9,10],[10,0],[10,11],[11,10],[10,8],[8,3],[3,1]]'); | |
// Convert paths to a hash: from -> [to] | |
$newPaths = array(); | |
foreach($paths as $path) { | |
if (!$newPaths[$path[0]]) $newPaths[$path[0]] = array(); | |
array_push($newPaths[$path[0]], $path[1]); |
This file contains hidden or 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 Dictionary { | |
function __construct($filename) { | |
$this->filename = $filename; | |
$this->sortedFilename = "${filename}.sorted"; | |
} | |
function search($search) { | |
if (!file_exists($this->sortedFilename)) { | |
$this->sortWords(); |
This file contains hidden or 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 Tree { | |
function add($value) { | |
if (!isset($this->value)) { | |
$this->value = $value; | |
return; | |
} | |
if ($value < $this->value) { |
This file contains hidden or 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
<? | |
/* | |
* Encrypts any number into a 10-digit cypher. | |
* Oh, 10 here means 10 in a random base. | |
*/ | |
class Encrypter | |
{ | |
function encrypt($num) | |
{ | |
$str = ""; |
This file contains hidden or 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 Compressor { | |
function compress($input, $output) { | |
$input = fopen($input, 'r'); | |
$output = fopen($output, 'w'); | |
while($line = fread($input, 8)) { | |
$lineLength = strlen($line); | |
for($i = 0; $i < $lineLength; $i += 8) { | |
$n = 0; |
This file contains hidden or 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
%Bar = type { i32 } | |
%Foo = type { %Bar* } | |
@.str5 = private constant [4 x i8] c"%d\0A\00", align 1 | |
declare i32 @printf(i8* nocapture, ...) nounwind | |
define i32 @main() ssp { | |
entry: | |
%Bar.i.i.i.i = alloca %Bar, align 8 |
This file contains hidden or 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 | |
APP_PATH = File.expand_path('../../config/application', __FILE__) | |
require File.expand_path('../../config/boot', __FILE__) | |
require File.expand_path('../../config/environment', __FILE__) | |
require 'csv' | |
filename = File.expand_path('../FOSA-Table.csv', __FILE__) | |
rows = CSV.read filename | |
rows = rows[1 .. -1] |
OlderNewer