Skip to content

Instantly share code, notes, and snippets.

View blixt's full-sized avatar
🗺️
Exploring

Blixt blixt

🗺️
Exploring
View GitHub Profile
@blixt
blixt / testasm.html
Created August 2, 2014 21:00
Slow asm.js procedure
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>asm.js</title></head>
<body>
<script>
function murmurhash3(stdlib, foreign, heap) {
"use asm";
var int32 = new stdlib.Int32Array(heap);
@blixt
blixt / Alea(2)
Created August 3, 2014 07:31
Dieharder run on procedural Alea with two seeds (500,000,000 values)
./randout.js --prng Procedural --count 500000000 > proc-alea2.txt && dieharder -g 202 -f proc-alea2.txt -a
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input| proc-alea2.txt| 3.77e+06 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
diehard_birthdays| 0| 100| 100|0.09460678| PASSED
@blixt
blixt / index.js
Last active December 29, 2020 14:32
requirebin sketch
var procedural = require('procedural');
var avatar = procedural('avatar')
// The block size is just visual, so it shouldn't affect randomization.
.doNotHash('blockSize')
// The username is needed to create a unique avatar for every user.
.takes('username')
// Size, in blocks. Different sizes will create different avatars.
.takes('size', function validate(avatar, blocks) {
// Ensure that size is a positive integer divisible by 2.
var pocket = require('pocket');
// Traits just need to implement an interface and can be instances or singletons (see anonymous trait below for
// interface).
var controller = require('./traits/controller');
var health = require('./traits/health');
var score = require('./traits/score');
var verlet = require('./traits/verlet');
var player = pocket.entity({name: 'Blixt'});
@blixt
blixt / flask_cors.py
Created August 16, 2014 18:24
How to add CORS support to a Flask app in 9 lines of code
def add_cors_headers(response):
response.headers['Access-Control-Allow-Origin'] = '*'
if request.method == 'OPTIONS':
response.headers['Access-Control-Allow-Methods'] = 'DELETE, GET, POST, PUT'
headers = request.headers.get('Access-Control-Request-Headers')
if headers:
response.headers['Access-Control-Allow-Headers'] = headers
return response
app.after_request(add_cors_headers)
@blixt
blixt / Twinder.md
Last active August 29, 2015 14:11
Twinder

Twinder

Optimize your Twitter feed.

Basic idea

  1. Authenticate to access a user's Twitter feed
  2. Display the feed as Twitter does
  3. Allow the user to swipe left or right on any tweet
    Left = indicate that you dislike the tweet
@interface SwipeableTableViewCell : UITableViewCell <UIScrollViewDelegate>
// Create the scroll view which enables the horizontal swiping.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.contentSize = self.bounds.size;
scrollView.contentInset = UIEdgeInsetsMake(0, 160, 0, 0);
scrollView.delegate = self;
scrollView.scrollsToTop = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
[self.contentView addSubview:scrollView];
// Set up main content area.
UIView *contentView = [[UIView alloc] initWithFrame:scrollView.bounds];
contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
contentView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:contentView];
self.scrollViewContentView = contentView;
// Put a label in the scroll view content area.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectInset(contentView.bounds, 10, 0)];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// Set up the container for the buttons that appear when swiping.
UIView *buttonsView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 160, self.bounds.size.height)];
buttonsView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.buttonsView = buttonsView;
[self.scrollView insertSubview:buttonsView atIndex:0];
// Create two action buttons and put them in the container.
UIButton *yesButton = [UIButton buttonWithType:UIButtonTypeCustom];
yesButton.autoresizingMask = UIViewAutoresizingFlexibleHeight;
yesButton.backgroundColor = [UIColor greenColor];