Skip to content

Instantly share code, notes, and snippets.

View straps's full-sized avatar

Francesco straps

View GitHub Profile
@straps
straps / https2http_proxy.js
Last active November 3, 2022 09:58
Very simple unsecure self-signed HTTPS to HTTP nodejs proxy
var httpProxy = require('http-proxy');
var pem = require('pem');
pem.createCertificate({ days: 1, selfSigned: true }, function (err, keys) {
var httpsOptions = {
key: keys.serviceKey,
cert: keys.certificate
};
httpProxy.createServer({
@straps
straps / dbmon-simple-function-call.js
Last active August 29, 2015 13:56
Simple dbmon usage sample to call a callback function on database table insert/update/delete/truncate
//PARAMETERS TO BE CHANGED
var PGCONN='tcp://postgres:password@localhost/database',
TABLE='testtable',
KEYNAME='id',
KEYTYPE='integer';
pg=require('pg'),
cli=new pg.Client(PGCONN),
dbmon=require('dbmon');
@straps
straps / simple-crawler.js
Created June 7, 2013 08:00
Based on the fantastic node-crawler plugin ( https://github.com/sylvinus/node-crawler ) Requires: npm install crawler Usage: node simple-crawler.js URL EXTENSIONS Example: node simple-crawler.js http://www.omgubuntu.co.uk/ jpg,png Find links for every page and subpages in URL and generates an URL list you can copy to a file and download with wge…
var Crawler = require("crawler").Crawler;
//console.argv=['node', 'app.js', url, ext]
if (process.argv.length < 4) {
console.log('Usage: ' + process.argv[0] + ' ' + process.argv[1] + ' URL EXT');
console.log('Example: ' + process.argv[0] + ' ' + process.argv[1] + ' http://www.omgubuntu.co.uk/ jpg,png');
process.exit(1);
}
var url = process.argv[2],
@straps
straps / frequenza
Created January 2, 2012 13:37
charterTooltipFormatt
!!{
chart:{zoomType: 'x', type:'area'},
navigator:{
xAxis:{
labels:{
formatter:function(){return this.value*2;}
},
ordinal:false
}
},
@straps
straps / dataset1.js
Created September 1, 2011 09:30
Hicharts demo datasets
var dataset1=[0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,10.408963,4.894694,1
@straps
straps / nodejs-mongodb-step
Created April 8, 2011 10:27
Node.js, mongodb and step module integration
/** Use Step to interact with a MongoDB database avoiding too many confusing callbacks,
requires: npm install mongodb step
*/
var mongo = require('mongodb'),
db=new mongo.Db('test', new mongo.Server('localhost', 27017, {}), {}),
step=require('step'),
col;
step(
function open(){
@straps
straps / nodebug
Created April 2, 2011 13:14
Node.js debugging script that uses node-inspector
#!/bin/bash
#Usage: nodebug app.js
node-inspector &
google-chrome http://127.0.0.1:8080/debug?port=5858
node --debug-brk $1
@straps
straps / SimplestWidget_Widget.php
Created November 12, 2010 00:14
Abstract class to create easily wordpress widgets, documented here http://www.strx.it/2010/11/wordpress-widgets-template/
<?php
class SimplestWidget_Widget extends Strx_Widget {
function w_id(){ return 'simplest-widget'; }
function w_name(){ return 'My Simplest Widget'; }
/** Return the dashboard admin form */
function w_form($instance){
return '<p>'.$this->w_form_input($instance, 'title').'</p>';
}
@straps
straps / debounce-fn
Created November 3, 2010 11:50
debounce
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
//Monitor bidders and bid for you; use jQuery ajax events capabilities
console.clear();
(function($){
$('#header_container')
.add('div.auction_related_list')
.add('div#footer_container')
.remove();
var id=parseInt($('div.auction_top_cont td:last').text().match(/[0-9]+/)[0],10),