Skip to content

Instantly share code, notes, and snippets.

View andrewvc's full-sized avatar

Andrew Cholakian andrewvc

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <unistd.h>
typedef struct
{
int num;
int state;
} Pin;
@andrewvc
andrewvc / gist:334688
Created March 16, 2010 23:56
JS Single Request Image Preloader
//Preload images one at a time
(function($) {
$.sPreLoad = {
loaded: new Array, //Images that have been loaded
loading: null, //Image currently loading
unloaded: new Array, //Images not yet loaded
run: function () {
//Load all the arguments into unloaded
$(arguments).each(function(i,url) {
$.sPreLoad.unloaded.push(url);
//Don't do this!
var file = 'myFile.txt'; // Executes First
fs.readFile(file, function () {
sys.write("Hi"); // Executes Third
});
sys.write("BYE") //Executes Second
http.createServer(function(req, res) {
var ip = req.connection.remoteAddress;
paperboy
.deliver(WEBROOT, req, res)
.addHeader('Expires', 300)
.addHeader('X-PaperRoute', 'Node')
.before(function() {
sys.log('Recieved Request')
})
.after(function(statCode) {
exports.deliver = function (webroot, req, res) {
var
stream,
fpRes = exports.filepath(webroot, url.parse(req.url).pathname),
fpErr = fpRes[0],
filepath = fpRes[1],
errorCallback,
headerFields = {},
addHeaderCallback,
delegate = {
//Simple (slow) way to transfer binary data
fs.createReadStream(filepath,{'flags': 'r', 'encoding':
'binary', 'mode': 0666, 'bufferSize': 64 * 1024})
.addListener("data", function(chunk){
res.write(chunk, 'binary');
})
.addListener("close",function() {
res.close();
})
@andrewvc
andrewvc / iptables.sh
Created May 13, 2010 21:23
Minimalist iptables init script
#!/bin/bash
#Simple iptables init script.
#Config
iptables_path="/sbin"
iptables="$iptables_path/iptables"
iptables_save="$iptables_path/iptables-save"
iptables_restore="$iptables_path/iptables-restore"
iptables_rules="/etc/iptables_rules"
@andrewvc
andrewvc / ssh-tunnel-init.rb
Created May 13, 2010 21:44
Simple init script for creating an ssh tunnel
#!/usr/bin/env ruby
#Init script for setting up a ssh tunnel
#Remote Port
tun_port = 123
#Local port to use
tun_lport = 1234
#Remote User
tun_user = 'username'
#Remote Host
# include this in application controller
module Authentication
protected
# Inclusion hook to make #current_user and #signed_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_user, :signed_in?, :authorized? if base.respond_to? :helper_method
end
# Returns true or false if the user is signed in.
module SendgridToolkit
class Bounces < AbstractSendgridClient
def retrieve(options = {})
options.each {|k,v| options[k] = 1 if k.to_s == 'date' && v == true}
api_post('bounces','get',options)
end
def delete(options = {})
response = api_post('bounces','delete',options)
raise BounceEmailDoesNotExist if response['message'].include?('does not exist')
response