Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Macagare
Macagare / download.js
Created March 16, 2013 12:26
JS: download file via node.js
var http = require('http');
var url = require('url');
var fs = require('fs');
var XmlStream = require('xml-stream');
var config = require('./config.json'); // already parsed
var downloadFile = function( targetUrl ) {
var xmlItem = "";
var timestamp = parseInt( new Date().getTime() / 1000 );
var options = {
@Macagare
Macagare / server.js
Created March 16, 2013 11:30
JS: create simple node.js server
var http = require('http');
http.createServer( function( req, res ) {
res.writeHead( 200, { 'Content-Type' : 'text/plain' } );
res.end( 'Hello World\n' );
} ).listen( 1337, '127.0.0.1' );
console.log( 'Server running at http://127.0.0.1:1337/' );
@Macagare
Macagare / idle.js
Created March 5, 2013 10:23
JS: idle timer with callback
( function() {
var timeoutDuration = 30;
var mouseMoved = 0;
var keyPressed = 0;
var getDocument = function() {
if ( window ) {
return window.document;
}
@Macagare
Macagare / gist:5040487
Created February 26, 2013 17:49
CF: convert list to numeric list
/**
* convert list to a list with numeric elements
*
* @param required string numList source list with elements]
* @return list with numeric items
*/
string function toNumericList( required string numList ) {
var numListLen = listLen( arguments.numList );
var result = "";
if ( numListLen > 0 ) {
@Macagare
Macagare / gist:5037410
Last active December 14, 2015 05:48
OpenBD: query builder in cfscript
/**
* Build query string and parameter array by using the placeholders like "__name__".
* It is mandatory to use sqlQuery or sqlName. Otherwise no sql will be used!
*
* @param optional string sqlQuery pass a query string to read and convert
* @param optional string sqlName pass the name of the global sql struct property instead of sqlQuery
* @param optional struct params map struct with key to replace and value to use in sql properties array
* @return a struct containing the processes "sql" as string and the "params" as array
*/
struct function queryMake( string sqlQuery, string sqlName, struct params ) {
@Macagare
Macagare / gist:5036977
Created February 26, 2013 08:29
TERMINAL: search in files content for string
find . -iname '*.cfc' | xargs grep 'string' -sl
find . | xargs grep 'string' -sl
@Macagare
Macagare / .vimrc
Last active December 10, 2015 21:08
vim configuration (update ~/.vimrc)
"Status line
set statusline=%F%m%r%h%w\ %{&ff}\ %Y\ a/h:%03.3b/%02.2B\ %04l,%04v\ %p%%\ %L\ lines
set laststatus=2
"Tabstop
set tabstop=4
set shiftwidth=4
set expandtab
set backspace=indent,eol,start
@Macagare
Macagare / gist:4484890
Created January 8, 2013 15:55
JS: class documentation
/**
* @class Acme.TYPO3.Foo.ClassWithConstructor
*
* This class has a constructor!
*
* @namespace Acme.TYPO3.Foo
* @extends TYPO3.TYPO3.Core.SomeOtherClass
*
* @constructor
* @param {String} id The ID which to use
@Macagare
Macagare / gist:4484888
Created January 8, 2013 15:55
JS: method documentation
/**
* This is a method declaration; and the
* explanatory text is followed by a newline.
*
* @param {String} param1 Parameter name
* @param {String} param2 (Optional) Optional parameter
* @return {Boolean} Return value
*/
@Macagare
Macagare / gist:4345160
Created December 20, 2012 12:59
Javascript: check for html5 via jquery
function isHtml5(){
var test_canvas = document.createElement("canvas") //try and create sample canvas element
return (test_canvas.getContext)? true : false //check if object supports getContext() method, a method of the canvas element
}