Skip to content

Instantly share code, notes, and snippets.

@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.
@johncant
johncant / .vimrc
Last active December 15, 2015 08:09
Syntax highlighting for KSP's ProgCom plugin
" Add this to your ~/.vimrc
autocmd BufRead,BufNewFile */PluginData/ProgCom/* set filetype=KSPProgComASM
@johncant
johncant / .rspec
Created April 9, 2013 12:51
Colourise your jenkins CI output for a Ruby on Rails app
# Put this in your .rspec for verbose and coloured output. Don't include this comment.
--colour --format documentation
@johncant
johncant / attributify.rb
Created July 22, 2013 17:58
This simple controller mixin allows you to lose the "_attributes" suffix when POST/PUTting data to your API, while maintaining the same nested attribute model behaviour. Simply replace params[:posts] with attributify(:posts) in your controllers. The old behaviour should still work.
module Attributify
def attributify(key, unprocessed=params[key])
if unprocessed.is_a? Hash
specific_params = {}
unprocessed.each do |k,v|
if (v.is_a?(Hash) && !k.to_s.match(/_attributes$/)) or (v.is_a?(Array) && !k.to_s.match(/_ids$/))
# Nested, so suffix with '_attributes'
specific_params["#{k}_attributes".to_sym] = attributify(key, v)
@johncant
johncant / config__initializers__send_emails.rb
Created September 12, 2013 13:19
Send emails with MS Exchange
# Use whatever your sysadmin says your settings are supposed to be
# ...
# ...
# The problem we had was that the SMTP server our outsourced sysadmin
# would send emails to Gmail, but they would not be received by the MS
# Exchange that he had set up for us. Our Rails mailer config was
# causing a spurious value in the SMTP "MAIL FROM" statement. This
# fixes it:
@johncant
johncant / picasso
Created October 23, 2013 17:43 — forked from lalaalaaa/picasso
"If you know exactly what you're going to do, what's the good of doing it? Since you know, the exercise is pointless. It is better to do something else."
-- Picasso
@johncant
johncant / Makefile.am
Created January 10, 2014 16:15
Use GNU autotools to call node-gyp to build a native node module
bin_PROGRAMS = some_node_module
some_node_module$(EXEEXT):
-cd $(NODE_MODULE_DIR) && node-gyp build
clean-local:
-cd $(NODE_MODULE_DIR) && node-gyp clean
@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.