This is a simple chat-like program using pub-sub pattern, backed by PostgreSQL's LISTEN/NOTIFY command.
publish message to foo
channel from user nickname
.
$ python pub.py foo nickname
PUBLISH to channel #foo
# We have a function that loads some resource. It might get called multiple times by our application, for example a web server. | |
# We use a stored promise to serve as both a cache and a hook for multiple callers to get the same result | |
# JavaScript version at the bottom | |
Q = require 'q' | |
loadPromise = null | |
doLoad = -> | |
if not loadPromise | |
# get a fresh result | |
loadPromise = Q.delay(1000).then -> Date.now() | |
# after 1 second clear cache |
export default x=>document.createElement('a').href=x |
Note: replace {{server}} with your domain or ip
ssh -i key.pem ec2-user@{{server}}
sudo -i
// Inspired by https://github.com/logicalparadox/backbone.iobind/blob/master/lib/sync.js | |
// Overwrite Backbone.sync method | |
Backbone.sync = function(method, model, options){ | |
// create a connection to the server | |
var ws = new WebSocket('ws://127.0.0.1:1234'); | |
// send the command in url only if the connection is opened | |
// command attribute is used in server-side. | |
ws.onopen = function(){ |
/** | |
* More info? | |
* [email protected] | |
* http://aspyct.org | |
* | |
* Hope it helps :) | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>App Redirection</title> | |
</head> | |
<body> | |
<!-- | |
NOTE: This was a great hack in days gone by, but now both Apple and Google have improved their support for custom | |
protocol handlers. |
/* Pixel Perfect CSS Rotation */ | |
body { | |
text-align: center; | |
} | |
.clock { | |
display: inline-block; | |
background: black; | |
border-radius: 100%; | |
width: 101px; | |
height: 101px; |
var net = require('net') | |
var sock = net.connect(1337) | |
process.stdin.pipe(sock) | |
sock.pipe(process.stdout) | |
sock.on('connect', function () { | |
process.stdin.resume(); | |
process.stdin.setRawMode(true) |
// Get a reference to the image element | |
var elephant = document.getElementById("elephant"); | |
// Take action when the image has loaded | |
elephant.addEventListener("load", function () { | |
var imgCanvas = document.createElement("canvas"), | |
imgContext = imgCanvas.getContext("2d"); | |
// Make sure canvas is as big as the picture | |
imgCanvas.width = elephant.width; |