Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Cholakian andrewvc

View GitHub Profile
View lightshow.c
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <unistd.h>
typedef struct
{
int num;
int state;
} Pin;
@andrewvc
andrewvc / gist:334688
Created Mar 16, 2010
JS Single Request Image Preloader
View gist:334688
//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);
View gist:358378
//Don't do this!
var file = 'myFile.txt'; // Executes First
fs.readFile(file, function () {
sys.write("Hi"); // Executes Third
});
sys.write("BYE") //Executes Second
View PaperboyDelegateExample.js
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) {
View node_delegate_example.js
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 = {
View node_reads.js
//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
Minimalist iptables init script
View iptables.sh
#!/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
Simple init script for creating an ssh tunnel
View ssh-tunnel-init.rb
#!/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
View authentication.rb
# 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.
View SendgridToolkitBounces.rb
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
You can’t perform that action at this time.