Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / constant.rb
Created February 28, 2013 22:57
constant in ruby
require 'pp'
CONSTANT="value";
foo = { };
foo[CONSTANT] = CONSTANT;
pp foo;
@earino
earino / results.pl
Created February 28, 2013 19:53
Results of the run
$VAR1 = {
'readonly' => sub {
use warnings;
use strict 'refs';
my $i = 0;
if (defined $test_hash{$READONLY_KEY}) {
if ($test_hash{$READONLY_KEY} eq $READONLY_VALUE) {
$i++;
}
}
@earino
earino / constant_shootout.pl
Created February 28, 2013 19:47
Constant Shootout
#!/usr/bin/env perl
use warnings;
use strict;
use Dumbbench;
use Readonly;
use Const::Fast;
use Data::Dumper;
$Data::Dumper::Deparse = 1;