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
cat("\014") | |
library(base) | |
if(require(tm) == FALSE) { | |
print("Attempting to install TM support..."); | |
install.packages("tm") | |
library(tm); |
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
<?php | |
$input = "Warped text!"; | |
$width = 200; | |
$height = 200; | |
// Allocate initial image with a solid white background. | |
$original = imagecreatetruecolor($width, $height); | |
imagefill($original, 0, 0, imagecolorallocate($original, 255, 255, 255)); |
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
define(function(require) { | |
/// Here's a scene I baked earlier. Bunch of cubes and a plane. | |
/// | |
///// 6 float triplets | |
/// | |
/// struct Face { | |
/// Vector3 a; | |
/// Vector3 b; | |
/// Vector3 c; |
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
Vector2 primo(int num) { | |
std::deque<int> primes; | |
const int root = (int) std::sqrt(num); | |
std::function<void(int)> recurse; | |
// Mostly from: http://www.coderenaissance.com/2011/06/finding-prime-factors-in-javascript.html | |
recurse = [&primes, &recurse, root] (int num) -> void { |
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
// Initial seed. | |
var x = 42; | |
function rand() { | |
// Old random number becomes next seed. | |
x = (1103515245 * x + 12345) % 2147483648; | |
// Generate a floating point, then modulo to only keep |
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
node::insert(int value) { | |
// Value falls in range | |
if(value >= this.min && value <= this.max) { | |
} | |
// Extend range | |
if(value == this.min - 1) { | |
this.min = 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
struct Textures { | |
static GLuint LoadPNG(const std::string& filename) { | |
if( ! FileExists(filename)) { | |
Exit("Cannot open png: %s.", filename.c_str()); | |
} | |
FILE* fp = ::fopen(filename.c_str(), "r"); | |
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); |
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
LeastSquaresLinearRegression: function(data, getter) { | |
// Assign a default trivial case getter: | |
if( ! getter) { | |
getter = function(row) { | |
return row; | |
}; | |
} | |
var xy = 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
// Quick test to see who converges quicker | |
// squared error | |
function e(w, t, x, y) { | |
return Math.pow(t - w * x - w*w*y, 2); | |
} | |
// e's derivative | |
function d(w, t, x, y) { | |
return 2 * (t - w * x - w*w * y) * (-x - 2*w*y); |
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
cat("\014") | |
library(class) | |
# I like boolean support. | |
no <- 0 | |
yes <- 1 | |
# Entry to clasify | |
test <- c( | |
"cat", # The correct class |