Skip to content

Instantly share code, notes, and snippets.

@earino
earino / fibo.js
Created April 8, 2013 19:38
least readable javascript fibonacci sequence in javascript?
function fib( n ) {
var a = 1, b = 1;
for (i = 3; i <= n; i++) {
b = [a, a += b][0];
}
return n == 0 ? 0 : a;
}
@earino
earino / foo.pl
Created May 3, 2013 18:09
column figure outer for sandy
#!/usr/bin/env perl
#
use warnings;
use strict;
{
print "How many items: ";
my $items = <STDIN>;
print "How many columns: ";
my $columns = <STDIN>;
@earino
earino / test.c
Created July 2, 2013 22:44
How does this work?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv) {
printf("Where exactly " "(and by exactly i "
"clearly mean here) "
"is the syntax error?\n");
exit(1);
}
@earino
earino / test.asm
Created July 2, 2013 22:59
Disassembled output
.file "test.c"
.section .debug_abbrev,"",@progbits
.Ldebug_abbrev0:
.section .debug_info,"",@progbits
.Ldebug_info0:
.section .debug_line,"",@progbits
.Ldebug_line0:
.text
.Ltext0:
.cfi_sections .debug_frame
@earino
earino / gist:6336302
Created August 25, 2013 21:04
Nokogiri fails me :(
Eduardos-MacBook-Pro:~ earino$ nokogiri
rbenv: nokogiri: command not found
Eduardos-MacBook-Pro:~ earino$ gem install nokogiri
Building native extensions. This could take a while...
Successfully installed nokogiri-1.6.0
1 gem installed
Installing ri documentation for nokogiri-1.6.0...
Installing RDoc documentation for nokogiri-1.6.0...
Eduardos-MacBook-Pro:~ earino$ rbenv rehash
Eduardos-MacBook-Pro:~ earino$ nokogiri
@earino
earino / string_slice.R
Created January 6, 2014 00:39
R native string slice implementation.
s <- "some source text..."
cutpoints <-data.frame(start=text$start, end=text$end)
keeps <- data.frame(start=c(1, cutpoints$end+1), end=c(cutpoints$start-1, nchar(s)))
pieces <- apply(keeps, 1, function(x) substr(s, x[1], x[2]))
sliced_string <- paste(pieces, collapse="")
@earino
earino / string_slicer.cpp
Created January 6, 2014 00:43
String Slicer in C++
#include <Rcpp.h>
#include <iostream>
using namespace Rcpp;
using namespace std;
.
// [[Rcpp::export]]
std::string string_slicer( std::string input, std::vector< int > start, std::vector< int > end) {
std::string working_copy = input;
for(std::vector<int>::size_type i = start.size() - 1; i != (std::vector<int>::size_type) -1; i--) {
@earino
earino / calling.R
Created January 6, 2014 00:44
Calling C++ from R
sourceCpp('../src/string_slicer.cpp')
sliced_string <- string_slicer(s, cutpoints$start, cutpoints$end)
#!/usr/bin/env perl
use warnings;
use strict;
use Data::Dumper;
my @records = ();
my $now = time();
my $weeks = 604800 * 52;
@earino
earino / foo.py
Created February 4, 2014 03:30
Logistic Regression Example from http://spark.incubator.apache.org/examples.html
points = spark.textFile(...).map(parsePoint).cache()
w = numpy.random.ranf(size = D) # current separating plane
for i in range(ITERATIONS):
gradient = points.map(
lambda p: (1 / (1 + exp(-p.y*(w.dot(p.x)))) - 1) * p.y * p.x
).reduce(lambda a, b: a + b)
w -= gradient
print "Final separating plane: %s" % w