Skip to content

Instantly share code, notes, and snippets.

@halferty
halferty / compile_webassembly.sh
Created September 19, 2017 01:30
Compile C++ to webassembly. Uses LLVM, binaryen, and wabt. This sequence of commands is ridiculous, but if you want the memory buffer exported from your C++ code, you'll need this.
#!/bin/bash
/Users/ehalferty/objc/build/bin/clang++ -emit-llvm --target=wasm32 -Oz src/cxx/test.cxx -c -o src/cxx/test.ll
llc src/cxx/test.ll -march=wasm32 -filetype=asm -o src/cxx/test.s
s2wasm src/cxx/test.s > src/cxx/test.wat
wat2wasm src/cxx/test.wat -o src/wasm/test.wasm
@halferty
halferty / App.ts
Last active September 15, 2017 16:55
Loading data into / out of webassembly runtime (test.wat takes a 4096-byte buffer and adds 5 to each byte)
// Load some sample WASM.
const wasm = require("wasm/test.wasm");
WASMHelper.runWat(wasm);
@halferty
halferty / install_mvn_3_1_1.sh
Created July 6, 2017 23:47 — forked from aaalaniz/install_mvn_3_1_1.sh
Install Maven 3.1.1
# Install to home directory
cd ~
# Extract the package
wget http://mirror.metrocast.net/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz
tar -xf apache-maven-3.1.1-bin.tar.gz
# Install mvn to path
M2_HOME=$HOME/apache-maven-3.1.1
echo -e "\n# Maven 3.1.1 Setup" >> ~/.bashrc
@halferty
halferty / generatorsexample.js
Created June 9, 2017 20:42
JS Generators example
function* exampleGenerator(i) {
yield i + 1;
yield i + 2;
yield i + 3;
}
function run(iter) {
let done = false;
while (!done) {
@halferty
halferty / b64
Created June 7, 2017 20:18
Base-64 encode a file
#!/usr/bin/env ruby
require "base64"
file_name = ARGV[0]
data = File.read file_name
puts Base64.encode64 data
@halferty
halferty / test.sh
Created May 1, 2017 16:52
Test SQS push with EC2 temporary credentials
(export AWS_ACCESS_KEY_ID=$(ruby -e "require \"json\"; puts JSON.parse(\`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<IAM group>\`)[\"AccessKeyId\"]"); export AWS_SECRET_ACCESS_KEY=$(ruby -e "require \"json\"; puts JSON.parse(\`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<IAM group>\`)[\"SecretAccessKey\"]"); export AWS_SESSION_TOKEN=$(ruby -e "require \"json\"; puts JSON.parse(\`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<IAM group>\`)[\"Token\"]"); export AWS_DEFAULT_REGION="us-east-1"; aws sqs send-message --queue-url "https://sqs.us-east-1.amazonaws.com/<rest of queue URL>" --message-body "Test")
@halferty
halferty / .bashrc
Created April 28, 2017 17:55
Unescape URLs quickly
alias unescape='ruby -e "require \"uri\";puts URI::unescape ARGV[0]"'
@halferty
halferty / disable_sprockets_cache_in_dev.rb
Last active April 17, 2017 20:55
Disable rails sprockets cache in development (probably so it's contents don't show up in your IDE's search results)
# in config/initializers/disable_sprockets_cache_in_dev.rb
if Rails.env.development?
module Rails
class Application
def assets
@assets ||= Sprockets::Environment.new(root.to_s) do |env|
env.version = ::Rails.env
path = "#{config.root}/tmp/cache/assets/#{::Rails.env}"
@halferty
halferty / adbfun.ino
Last active January 17, 2017 08:55
Arduino Apple ADB fun
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c\n"
#define BYTE_TO_BINARY(val) \
(val & 0x80 ? '1' : '0'), \
(val & 0x40 ? '1' : '0'), \
(val & 0x20 ? '1' : '0'), \
(val & 0x10 ? '1' : '0'), \
(val & 0x8 ? '1' : '0'), \
(val & 0x4 ? '1' : '0'), \
(val & 0x2 ? '1' : '0'), \
(val & 0x1 ? '1' : '0')
@halferty
halferty / run.rb
Created January 6, 2017 11:36
Simple pure-ruby standard-library-only HTTP server
#!/usr/bin/env ruby
require 'socket'
require 'json'
server = TCPServer.new '0.0.0.0', 8765
loop do
socket = server.accept
data = ""
while (line = socket.gets) && line != "\r\n"
data += line
end