This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var java = require('java'); | |
var util = require('util'); | |
// ------------------------------------------------- | |
// How to use AntiSamy from Node to sanitize HTML | |
// ------------------------------------------------- | |
// sanitizing HTML input is a science in itself. better not to reinvent the wheel | |
// the AntiSamy main website is https://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "uv.h" | |
// uv1.c | |
// compile with : gcc -o uv1 -I libuv/include -Wall uv1.c libuv/uv.a -lpthread -lm -lrt | |
#define CHECK(r, msg) \ | |
if (r) { \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use node 'child_process' to exec make | |
var exec = require('child_process').exec; | |
// register a custom task | |
grunt.registerTask('make','invoke external make',function() { | |
// set grunt task to async mode | |
var done = this.async(); | |
// execute make (or any other external executable for that matter) | |
exec('make',function(error,stdout,stderr) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var exec = require('child_process').exec; | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
jshint: { | |
// define the files to lint | |
files: ['gruntfile.js', 'main.js', 'src/**/*.js', 'test/**/*.js'], | |
// configure JSHint (documented at http://www.jshint.com/docs/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <node.h> | |
#include <string.h> | |
#include <v8.h> | |
using namespace v8; | |
unsigned long long count = 0; | |
// native blocking/compute intensive function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import shlex | |
import struct | |
import platform | |
import subprocess | |
def get_terminal_size(): | |
""" getTerminalSize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
"use strict"; | |
// tested with io.js 1.5.1 which supports ES6 'const' | |
// there are no mutable variables in the entire gist | |
const assert = require('assert'); | |
const util = require('util'); | |
const P = require('pointfree-fantasy'); | |
const map = P.map; | |
const compose = P.compose; | |
const Maybe = require('pointfree-fantasy/instances/maybe'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see results at https://labnotes.org/validate-your-assumptions/ | |
var http=require('http'); | |
var fs=require('fs'); | |
// read the file and make a list of the hostnames | |
var list=fs.readFileSync('hostnames.txt').toString().split('\r\n'); | |
// get from one host and process it | |
function get(a,i) { | |
if (i >= a.length) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdint> | |
#include <limits> | |
/** | |
USING TAGGED DISPATCH FOR GENERIC IF-THEN-ELSE | |
Or, sort of a contrived example that illustrates more or less how 'tagged disppatch' in the STL work | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// ================================================= | |
// a common question that pops up is | |
// 'why do my async functions use the final value of my loop variable instead of the one they are called with'? | |
// its because they refer directly to the loop variable and its last value | |
// the solutions are various ways to bind the loop variable in a new scope | |
// | |
// this gist shows different ways to handle a loop that spawns an async function that depends on the loop index | |
// ================================================= |
OlderNewer