Skip to content

Instantly share code, notes, and snippets.

@encryptio
encryptio / bf-reql.js
Last active Jul 15, 2016
Brainfuck interpereter in ReQL
View bf-reql.js
var charLookup = "??????????\n????????????????????? !?#$%&?()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[?]^_`abcdefghijklmnopqrstuvwxyz???~?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????";
var bailoutSteps = 60000;
r.expr({
program: "rot13 (from Wikipedia):"+
"-,+[ Read first character and start outer character reading loop"+
" -[ Skip forward if character is 0"+
" >>++++[>++++++++<-] Set up divisor (32) for division loop"+
" (MEMORY LAYOUT: dividend copy remainder divisor quotient zero zero)"+
View gist:e6c2375c12b68c261965
### Keybase proof
I hereby claim:
* I am encryptio on github.
* I am encryptio (https://keybase.io/encryptio) on keybase.
* I have a public key whose fingerprint is D72A 7DD7 B5E5 9821 8E15 37A6 2FBB F02B 4281 437B
To claim this, I am signing this object:
@encryptio
encryptio / test.c
Created Nov 2, 2015
Floating point weirdness
View test.c
// Compile and run in 32-bit mode:
// $ cc -Wall -m32 -o test test.c
// $ ./test
// false
//
// Contrast with 64-bit mode:
// $ cc -Wall -m64 -o test test.c
// $ ./test
// true
//
View server-cooperative.pl
#!/usr/bin/perl
use warnings;
use strict;
use AnyEvent;
use AnyEvent::Socket;
use Coro;
use Coro::Handle;
my %open;
View empty-trashes.pl
#!/usr/bin/perl
use strict;
use warnings;
sub spawn {
if ( !fork ) {
system @_ and die;
exit 0;
}
}
View gist:543182
- (void)loadImage {
NSURL *url = [db getImageURL:mnam node:nodeidx];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
[[URLHandler mainHandler] dataForURL:url sentTo:^(BOOL worked, NSData *data){
if ( !worked ) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Network Failure"
message:@"Couldn't download the comic. Make sure you're connected to a network."
View gist:491728
int pti = 0;
for (int i = 0; i < len; i++) {
float f = (float)i/len*sr;
if ( f < curve->pts[0].freq ) {
// before the first point
in[i].r = curve->pts[0].power;
} else if ( curve->pts[curve->ct-1].freq < f ) {
// after last point
in[i].r = curve->pts[curve->ct-1].freq;
} else {
View gist:491724
sub make_wantcurve {
my ($sr,$size,$pts) = @_;
my @points = sort { $a->[0] <=> $b->[0] } @$pts;
my $want = [];
FREQ: for my $i ( 0 .. $size-1 ) {
my $f = $i/$size*$sr;
if ( $f > $sr/2 ) {
$f = $sr-$f; # ah, imaginary numbers, how i love you so
View gist:491687
sub read_curve_from {
my ($fn) = @_;
my $fh;
if ( $fn eq "-" ) {
$fh = \*STDIN;
} else {
open $fh, "<", $fn or die "Couldn't open $fn for reading: $!";
}
return read_curve_string(do { local $/; <$fh> });
View gist:491686
#include "wantcurve.h"
#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
wantcurve *read_wantcurve_from_path(char *path) {
FILE *fh;
if ( (fh = fopen(path, "rb")) == NULL )