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
module SomeThing | |
class SomethingElse;end | |
def self.inside | |
x = AllTogetherDifferent.new | |
# Works because all constants are Global | |
puts x.inspect | |
# x = SomeThing::AllTogetherDifferent.new | |
# Produces in `inside': uninitialized constant SomeThing::AllTogetherDifferent (NameError) | |
x = SomeThing::SomethingElse::AllTogetherDifferent.new | |
puts x.inspect |
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
-- Lua object implemented with just functions. | |
function make(a,b) | |
return function(msg) | |
if msg == "a" then return a end | |
if msg == "b" then return b end | |
if msg == "mul" then | |
return function() | |
return a * b | |
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
package main | |
import ( | |
"fmt" | |
"net" | |
"time" | |
"bufio" | |
) | |
func handleConnection(conn net.Conn) { |
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 | |
function sum_csv($str,$sep,$col) { | |
return floatval(array_reduce(array_slice(explode("\n",$str),1), | |
function ($a,$l) use ($col,$sep) { | |
return $a + explode($sep,$l)[$col]; | |
})); | |
} | |
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
function splitNumber(n,l) { | |
if ( l == 1 ) { | |
return [n]; | |
} | |
var guess = Math.random(n / l + 1) * (((n/l) / 10 ) * 10); | |
return [guess].concat(splitNumber(n - guess,l - 1)) | |
} | |
// Test Code | |
for ( var i = 0; i < 10; ++i ) { | |
var test_case = Math.random(); |
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 | |
namespace Codeable; | |
function map_with_keys($cb,$a) { | |
$na = []; | |
foreach ($a as $k=>$v) { | |
list($nk,$nv) = call_user_func_array($cb,[$k,$v]); | |
$na[$nk] = $nv; | |
} | |
return $na; | |
} |
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 | |
function create_connection() { | |
$mysqli = new mysqli("localhost", "root", "xxx"); | |
if ( $mysqli->connect_errno ) | |
die( $mysqli->connect_error ); | |
$mysqli->set_charset('utf8'); | |
return $mysqli; | |
} | |
$conn = create_connection(); | |
$create_table = " |
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 <stdlib.h> | |
#include <stdio.h> | |
int main (int argc, char** argv) { | |
int *x = (int*)malloc(sizeof(int)); | |
*x = 3; | |
int *y = x; | |
printf("x: %d, y:%d\n",*x,*y); | |
free(x); | |
printf("x: %d, y:%d\n",*x,*y); | |
free(y); |
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
function flatten(array) { | |
// Because we are going to do this recursively, | |
// we start with the "end", in this case, it's any | |
// none-array value, we put it into an array, because | |
// we are recursively "merging" | |
if ( ! Array.isArray(array) ) | |
return [array]; | |
var results = []; | |
for ( var i in array ) { | |
results = results.concat( |
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 Node | |
attr_accessor :val,:nxt | |
def initialize(val,nxt) | |
@val = val | |
@nxt = nxt | |
end | |
end | |
def print_nodes(head) | |
while head do | |
puts head.val |
OlderNewer