Skip to content

Instantly share code, notes, and snippets.

View theycallmeswift's full-sized avatar

Swift theycallmeswift

View GitHub Profile
@theycallmeswift
theycallmeswift / blink_arduino_ex.ino
Last active December 20, 2015 07:39
BreakfastSerial Code Snippets
var cronJob = require('cron').CronJob;
new cronJob('00 09 * * * *', function(){
var data = Emails.where( { needsSending: true });
data.forEach(function(email) {
sendMessage(email);
});
}, null, true, "America/Los_Angeles");
@theycallmeswift
theycallmeswift / photo.js
Created June 20, 2013 23:17
Get random Tumblr Images from Programmer Ryan Gosling
module.exports = function getImage(cb) {
var request = require('request')
, callback = cb || function() {}
, tumblr_key = process.env.TUMBLR_KEY
, post = Math.floor((Math.random()*96))
, url = "http://api.tumblr.com/v2/blog/programmerryangosling.tumblr.com/posts?api_key=" + tumblr_key + "&type=photo&limit=1&offset=" + post;
request(url, function(err, res, body) {
try {
var image = JSON.parse(body).response.posts[0].photos[0].original_size.url;
@theycallmeswift
theycallmeswift / index.js
Created June 7, 2013 06:50
Convert PNG Base64 data to images
function createImage(data,cb) {
var img = new Image();
img.src = "data:image/png;base64," + data;
img.onload = function() {
cb(img);
}
}
from BreakfastSerial import Arduino, Led, Button
board = Arduino()
led = Led(board, 13)
button = Button(board, 8)
button.down(led.toggle)
var arduino = require("johnny-five")
, board = new arduino.Board()
, SendGrid = require('sendgrid').SendGrid
, sg = new SendGrid("your_sendgrid_username", "your_sendgrid_password");
board.on("ready", function() {
var button = new arduino.Button(8); // Button on pin 8
button.on("up", function() {
sg.send({
var request = require("request");
request({
uri: "http://data.mtgox.com/api/1/BTCUSD/ticker:80",
headers: {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, compress",
"User-Agent": "HTTPie/0.3.1"
},
timeout: 10000
{
"protocol": "JSON",
"awesome": true,
"stats": {
"number_of_wtfs": 0,
},
"complaints": null,
"reasons": ["simple", "fast"]
}
@theycallmeswift
theycallmeswift / sendgrid_proxy.js
Created March 4, 2013 17:08
A simple node sendgrid proxy
var express = require('express')
, app = express()
, SendGrid = require('sendgrid').SendGrid
, sg = new SendGrid(process.env.SENDGRID_USER, process.env.SENDGRID_PASS);
app.use(express.logger());
app.use(express.bodyParser());
app.post('/email', function(req, res) {
if(!req.body.to || !req.body.subject || !req.body.html) {
@theycallmeswift
theycallmeswift / gist:4968761
Created February 16, 2013 21:12
Get a random fact from the command line
alias fact="echo -ne '\033[36m'; curl -s randomfunfacts.com | grep '<i>' | sed 's/.*<i>\(.*\)<\/i>.*/\1/'; echo -ne '\033[0m';"