Skip to content

Instantly share code, notes, and snippets.

View oroce's full-sized avatar

Róbert Oroszi oroce

  • Budapest, Hungary
View GitHub Profile
@oroce
oroce / example1.js
Created November 28, 2012 21:33
Backbone.Router onbeforeroutechange
var Router = Backbone.Router.extend({
routes: {
"your-complex-form": "complexFormHandler",
"": "default"
},
complexFormHandler: function(){
if( !this.complexFormViewInstance ){
this.complexFormViewInstance = new ComplexFormViewInstance();
}
@oroce
oroce / slugify.js
Created January 20, 2013 17:57
using Iconv in node.js as slugifier
var Iconv = require( "iconv" ).Iconv,
fromLatinToUtf8 = new Iconv( "ISO-8859-1", "UTF-8" ),
removeAccent = new Iconv( "UTF-8", "US-ASCII//TRANSLIT//IGNORE" );
var stringWithAccents = "árvíztűrőtükörfúrógép"; // it's great hungarian word, it contains all the tricky characters
removeAccent.convert( stringWithAccents ).toString().replace( /"*'*:*~*/gm, "" ) === "arvizturotukorfurogep";
@oroce
oroce / geoip-lite updater.js
Created February 17, 2013 18:58
Update geop-lite data from countly installation.
var async = require( "async" ),
request = require( "request" ),
fs = require( "fs" ),
path = require( "path" ),
zlib = require( "zlib" ),
AdmZip = require( "adm-zip" ),
spawn = require( "child_process" ).spawn;
// http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/GeoLiteCity-latest.zip
// http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
@oroce
oroce / basic-usage.js
Last active April 1, 2017 15:12
This is just a proof of concept demo to parse haproxy log and put into Google Analytics.
var haproxyLog = new HaProxyLog({
port: process.env.PORT||3333
});
haproxyLog
.on( "up", console.log.bind( console, "Server is up" ) )
.on( "down", console.log.bind( console, "Server is down" ) )
.on( "backend-down", console.log.bind( console, "Backend is down" ) )
.on( "access-log", console.log.bind( console, "access log entry:" ) )
.on( "raw", function( message ){console.log( "this is the raw message:", message.toString() ) });
info: Welcome to Nodejitsu oroce
info: jitsu v0.9.7
info: It worked if it ends with Nodejitsu ok
info: Executing command logs app elvira
error: Error running command logs app elvira
error: Nodejitsu Error (500): Internal Server Error
warn: Error returned from Nodejitsu
error: Error: socket hang up
error: at createHangUpError (http.js:1344:15)
@oroce
oroce / package.json
Created March 20, 2013 19:36
nodejitsu expose-gc
{
"scripts": {
"start": "node --nouse-idle-notification --expose-gc app.js"
}
}
@oroce
oroce / runner.js
Last active December 15, 2015 07:19
expose gc on nodejitsu: you need to modify your npm start script too: "node runner.js"
var spawn = require( "child_process" ).spawn;
var env = process.env || {};
env.PORT = 3001;
var childProcess = spawn( "node", [
"--nouse-idle-notification",
"--expose-gc",
"app.js"
], {
env: env
});
var
express = require("express")
app = express()
sio = require("socket.io"),
server = require('http').createServer(app)
io = sio.listen(server);
server.listen(3333);
io.sockets.on('connection', function (socket) {
socket.broadcast.emit( "clients", io.sockets.clients().map(function(s){ return s.id; }));
@oroce
oroce / gist:5500941
Created May 2, 2013 08:32
nodefly crash
Error: not opened
at WebSocket.send (/my/folder/node_modules/nodefly/node_modules/socket.io-client/node_modules/ws/lib/WebSocket.js:175:16)
at Transport.WS.send (/my/folder/node_modules/nodefly/node_modules/socket.io-client/lib/transports/websocket.js:107:22)
at Transport.packet (/my/folder/node_modules/nodefly/node_modules/socket.io-client/lib/transport.js:178:10)
at Socket.packet (/my/folder/node_modules/nodefly/node_modules/socket.io-client/lib/socket.js:295:22)
at SocketNamespace.packet (/my/folder/node_modules/nodefly/node_modules/socket.io-client/lib/namespace.js:64:17)
at SocketNamespace.emit (/my/folder/node_modules/nodefly/node_modules/socket.io-client/lib/namespace.js:113:17)
at SocketNamespace.<anonymous> (/my/folder/node_modules/nodefly/lib/sockets.js:40:10)
at SocketNamespace.EventEmitter.emit [as $emit] (/my/folder/node_modules/nodefly/node_modules/socket.io-client/lib/events.js:165:15)
at SocketNamespace.onPacket (/my/folder/node_modules/nodefly/node_modules/