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 make_adder( left_operand ) { | |
return function ( right_operand ) { | |
return left_operand + right_operand; | |
}; | |
} | |
// so, you can say: | |
var plus_two = make_adder(2); | |
var plus_three = make_adder(3); | |
alert(plus_two(5)); //=> 7 |
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
void str_remove_char ( char array[], int c ) { | |
int i, j; | |
for ( i = j = 0; array[i]; ++i ) { | |
if ( array[i] != c ) | |
array[j++] = array[i]; | |
} | |
array[j] = '\0'; | |
} |
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> | |
void str_squeeze(char *s) { | |
int i, j; | |
char last = '\0'; | |
for ( i = j = 0; s[i]; last = s[i++] ) | |
if ( s[i] != last ) | |
s[j++] = s[i]; | |
s[j] = '\0'; | |
} |
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
// Benchmarking String Concatenation Comparing | |
// 1. Array.join | |
// 2. String concatenation with '+' | |
// Test Functions | |
function test_join(content) { return ['output.push(', content, ');'].join(''); }; | |
function test_str_concat(content) { return 'output.push(' + content + ');'; }; | |
// Test Strings | |
var SHORT_STRING = 'test'; |
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: allData(node) | |
// Concatenate all the text data of a node's children. | |
// | |
function allData(node) { | |
var data = ""; | |
if (node && node.firstChild) { | |
node = node.firstChild; | |
if (node.data) { data += node.data; } | |
while (node = node.nextSibling) { |
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
# Strip Similarities between two strings | |
module Kernel | |
# | |
# strip_similiar | |
# Strips the similiarities at the start and end of each | |
# of the given strings, returning a list of both of the | |
# stripped strings. | |
# |
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
int str_cmp( char *str1, char *str2 ) { | |
if ( !*str1 && !*str2 ) | |
return 0; | |
char a = *str1, b = *str2; | |
if( a >= 'a' && a <= 'z' ) | |
a -= 32; | |
if( b >= 'a' && b <= 'z' ) | |
b -= 32; |
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
# DATA is a global that is actually a | |
# File object containing the data | |
# after __END__ in the current | |
# script file. WHOA! | |
puts DATA.read | |
__END__ | |
I can put anything I want | |
after the __END__ symbol | |
and access it with the |
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 'rubygems' | |
require 'hpricot' # hpricot-0.6.164 | |
html = <<END | |
<html><head></head><body><table> | |
<tr><td>R0C0</td><td>R0C1</td><td>R0C2</td><td>R0C3</td></tr> | |
<tr><td>R1C0</td><td>R1C1</td><td>R1C2</td><td>R1C3</td></tr> | |
<tr><td>R2C0</td><td>R2C1</td><td>R2C2</td><td>R2C3</td></tr> | |
</table></body></html> | |
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
// Javascript Benchmark Declaring len inside and outside of a for loop | |
// Populate array with 0..100 | |
var arr = [] | |
for (var i=0; i<1e3; ++i) { arr[i] = i; } | |
// Declare len outside of the for | |
function outfor(a) { | |
var len = a.length; | |
for (var i=0; i<len; ++i); | |
} |
OlderNewer