Skip to content

Instantly share code, notes, and snippets.

@yawnt
yawnt / notification.js
Created May 14, 2012 18:34
notification
if(webkitNotifications && webkitNotifications.checkPermission() === 1) {
$('.menu > ul').append('<li><a href="javascript:webkitNotifications.requestPermission();location.reload()">Notifications</a>');
}
else if(webkitNotifications && webkitNotifications.checkPermission() === 0) {
var notificationCounter = Date.now();
setInterval(function() {
$.getJSON('/api/notification/unseen', function(data) {
data = data.notifications;
if(data.length === 0) return;
if(
yawn@xolotl:~/Codes/imago $ npm install
> browserjet@0.1.0 install /home/yawn/Codes/imago.jit.su/node_modules/browserjet
> ./install.py
--2012-06-09 18:55:49-- http://releases.browserjet.com/browserjet-linux-64bit-latest.tar.bz2
Resolving releases.browserjet.com (releases.browserjet.com)... 74.207.244.30
Connecting to releases.browserjet.com (releases.browserjet.com)|74.207.244.30|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17057998 (16M) [application/x-bzip2]
@yawnt
yawnt / console
Created July 14, 2012 11:57
Gist
[yawn@xolotl resourceful]$ node
> var m = require('./models/');
undefined
> m.User.create({username: 'pwd', password:'pwd',salt:'asd'}, function(e, i) { console.log(i); });
undefined
> { username: 'pwd',
salt: 'asd',
password: 'pwd',
ctime: 1342266826474,
mtime: 1342266826474,
@yawnt
yawnt / oautho.js
Created July 20, 2012 15:23
Node-oauth
var o = require('oauth');
var oauth = new o.OAuth2("BUH", "amhar9ekAKv5QLio", "http://localhost:8000/", "oauth/authorize", "oauth/token")
oauth.getAuthorizeUrl({redirect_uri: "http://localhost:8080/callback", response_type: "code" }) // visiti sta url dal browser e ti segni il codice che ritorna
oauth.getOAuthAccessToken("dcL30MMCj1QLz2kM", {grant_type: 'authorization_code', "redirect_uri": "http://localhost:8080/callback"}, function() { console.log(arguments); });
/*{ '0': null,
'1': '8IOsH9X73yiiv2CiqmqoASv0ECj4YHxQGkGmvz75UMf78IH9QFdd',
'2': undefined,
defmodule Bot do
alias :gen_tcp, as: Socket
def connect(server, port) do
{:ok, sock} = Socket.connect(server, port, [:binary, {:packet, 0}])
Socket.send sock, "NICK elixir_bot"
Socket.send sock, "USER elixir_bot 0 * elixir_bot"
Socket.send sock, "JOIN #testo"
receive do
{tcp, sock, data} -> IO.puts data
defmodule Bot do
alias :gen_tcp, as: Socket
def connect(server, port) do
{:ok, sock} = Socket.connect(server, port, [:binary, {:packet, :line}])
#Socket.send sock, "NICK elixir_bot"
#Socket.send sock, "USER elixir_bot 0 * elixir_bot"
#Socket.send sock, "JOIN #testo"
#do_loop(sock)
  end
@yawnt
yawnt / gist:3397183
Created August 19, 2012 19:30
async ee
var Emitter = require('events').EventEmitter;
exports.async = function(arr, fn, done) {
var todo = arr.length,
em = new Emitter();
em.on('done', function() {
if(!(--todo)) { done(); }
});
arr.forEach(function(item) {
@yawnt
yawnt / bah.js
Created September 8, 2012 21:09
Bah
// test
test(function(e, res) {
res.doSomething(function(err, herp) {
console.log('IMMA BE NESTED');
})
(nested, nested2);
})
(param, param2);
(function(e,t,n){function i(e){return e}function s(e){return decodeURIComponent(e.replace(r," "))}var r=/\+/g,o=e.cookie=function(r,u,a){if(u!==n){a=e.extend({},o.defaults,a),u===null&&(a.expires=-1);if(typeof a.expires=="number"){var f=a.expires,l=a.expires=new Date;l.setDate(l.getDate()+f)}return u=o.json?JSON.stringify(u):String(u),t.cookie=[encodeURIComponent(r),"=",o.raw?u:encodeURIComponent(u),a.expires?"; expires="+a.expires.toUTCString():"",a.path?"; path="+a.path:"",a.domain?"; domain="+a.domain:"",a.secure?"; secure":""].join("")}var c=o.raw?i:s,h=t.cookie.split("; ");for(var p=0,d;d=h[p]&&h[p].split("=");p++)if(c(d.shift())===r){var v=c(d.join("="));return o.json?JSON.parse(v):v}return null};o.defaults={},e.removeCookie=function(t,n){return e.cookie(t)!==null?(e.cookie(t,null,n),!0):!1}})(jQuery,document)
var http = require('http'),
mongodb = require('mongodb');
var db = new mongodb.Db('*********************', new mongodb.Server('alex.mongohq.com', 10086, {}));
var inc = 0;
db.open(function (err, db_p) {
if (err) { throw err; }
db.authenticate('nodejitsu', '********************', function (err, replies) {