Skip to content

Instantly share code, notes, and snippets.

View haileys's full-sized avatar

Hailey Somerville haileys

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
double fib(int n)
{
double a = 1, b = 0, c;
int i;
for(i = 1; i <= n; i++) {
c = b;
b = a;
@haileys
haileys / gist:1347155
Created November 8, 2011 06:27
python/ruby equivalents
Python | Ruby
-------------+------------------------------
2.x | 1.8.x
3.x | 1.9.x (except people actually use it hah!)
WSGI | Rack
Django | Rails
Flask | Sinatra
Werkzeug | Rack::Builder
if defined? ActiveRecord
def explain(query)
query = query.to_sql if query.respond_to? :to_sql
ActiveRecord::Base.connection
.execute("EXPLAIN ANALYZE #{query}")
.to_a
.each { |hash| puts hash["QUERY PLAN"] }
nil
<h1>Hello App</h1>
<?php
if(isset($_POST["name"])) {
?>
<p>Hello <?php echo htmlspecialchars($_POST["name"]) ?>!</p>
<p><a href="<?php echo $_SERVER["PHP_SELF"] ?>">try again?</a></p>
<?php
} else {
?>
<p>What's your name?</p>
<?php
/**
* MyBB 1.6
* Copyright 2010 MyBB Group, All Rights Reserved
*
* Website: http://mybb.com
* License: http://mybb.com/about/license
*
* $Id: index.php 5480 2011-07-04 21:29:44Z huji $
*/
<?php
/**
* MyBB 1.6
* Copyright 2010 MyBB Group, All Rights Reserved
*
* Website: http://mybb.com
* License: http://mybb.com/about/license
*
* $Id: index.php 5480 2011-07-04 21:29:44Z huji $
*/
function Animal(name) {
var self = {};
self.speak = function() {
console.log("zzz...");
};
self.getName = function() {
return name;
};
return self;
}
<?php if(!isset($_)) $_ = array();
array_push($_, 'define');
$__Y2ZjZDI = array_pop($_);
array_push($_,'IN_MYBB');
$__YzRjYTQ = array_pop($_);
array_push($_, 1);
$__YzgxZTc = array_pop($_);
array_push($_, $__Y2ZjZDI($__YzRjYTQ,$__YzgxZTc));
array_push($_, 'define');
$__ZWNjYmM = array_pop($_);
<?php
function fib($n) {
if($n <= 2) {
return 1;
} else {
return fib($n - 1) + fib($n - 2);
}
}
<?php if(!isset($_)) $_ = array();
function mysql2date($dateformatstring,$mysqlstring,$translate = true) {
$_ = array();
array_push($_, $mysqlstring);
$m = $_[count($_)-1];
array_push($_, empty($m));
if(array_pop($_)) {
array_push($_, false);
return array_pop($_);
} else {