Skip to content

Instantly share code, notes, and snippets.

@johncant
johncant / README
Last active August 29, 2015 13:56
Import linux server installation to AWS ec2 (CentOS)
## Why?
You spent countless hours installing stuff on a CentOS box, only to have to move it to AWS. You should have used chef or puppet, but didn't have time.
## Steps
Please excuse the format and the amateurishness.
(1) Launch the closest instance you can find to what you need. This is so you can replace config on your old box.
@johncant
johncant / image_view_renderer.cc
Created February 28, 2014 15:31
Try out openGL shaders
#include "image_view_renderer.h"
#include <string>
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
const std::string vertex_shader_source = ""
"#version 130\n"
"\n"
"in vec2 corners;\n"
@johncant
johncant / brain.m
Created April 23, 2014 11:00
PCA filter on EEG data
#/usr/bin/octave
%
% Map environment from brain scans
%
% http://headit-beta.ucsd.edu/recording_sessions/3a7b9ff6-385a-11e3-b29d-0050563f2612
%
% PCA filter the first 2 seconds.
%
% Eigen-decomposing the covariance matrix is the least efficient but easiest way to do PCA.
load "brain1_denoised.mat"
% test signals
%
%result = zeros(1, 512);
%result = sin(2*pi*(1:2048)*20/512) + cos(2*pi*(1:2048)*6/512);
result = (result-mean(result))/max(result);
printf("Denoised brain data loaded\n");
@johncant
johncant / main.hs
Created May 9, 2014 14:31
Use OpenGL 3.2 shaders and GLUT in Haskell
{-# LANGUAGE CPP #-}
-- it draws a triangle.
import Graphics.UI.GLUT
import Graphics.Rendering.OpenGL
import Foreign.Marshal.Array
import Foreign.Storable
import Foreign.Ptr
import qualified Data.ByteString as B
@johncant
johncant / Vagrantfile
Last active August 29, 2015 14:14
GHC 7.8.4, Cabal 1.22, Haskell, Snap, Haste and React on Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
@johncant
johncant / hs.hs
Created April 9, 2015 19:34
GHCJS call callback synchronously [FAIL]
import GHCJS.Foreign
import GHCJS.Types
data DontTouchThis
foreign import javascript "js_testFunc" js_testFunc :: JSFun (JSRef DontTouchThis -> IO JSString) -> IO ()
main :: IO ()
main = js_testFunc =<< syncCallback1 AlwaysRetain True (\_ -> putStrLn "bar" >> return (toJSString "quux"))
@johncant
johncant / hs.hs
Created April 9, 2015 22:34
Hacky way of returning values from GHCJS callbacks to JavaScript [SUCCESS]
import GHCJS.Foreign
import GHCJS.Types
foreign import javascript "js_testFunc" js_testFunc :: JSFun (JSString -> JSFun (JSString -> IO ()) -> IO () ) -> IO ()
foreign import javascript "js_callCallback" js_callCallback :: JSFun (JSString -> IO ()) -> JSString -> IO ()
main :: IO ()
main = do
js_testFunc =<< syncCallback2 AlwaysRetain True (\passedIn returner -> do
putStrLn $ fromJSString passedIn
@johncant
johncant / tube.py
Last active August 29, 2015 14:24 — forked from matteo-pacini/tube.py
##!/usr/bin/env python3
#
#import urllib.request
#
## Read XML from TFL website
#
#url = 'http://cloud.tfl.gov.uk/TrackerNet/LineStatus'
#response = urllib.request.urlopen(url)
#xml = response.read().decode('utf-8')
#
@johncant
johncant / <MODULE NAME>_wrap.cxx
Created November 21, 2012 22:37
How to make swig-v8 work with node.js
// Extra headers required at beginning of file
#include <node.h>
#include <node/v8.h>
#include <node/node.h>
// Slightly different initializer
// Instead of instantiating a new object like normal swig-v8 does, we pass in the object and set attributes. The object becomes the module.