Skip to content

Instantly share code, notes, and snippets.

View andris9's full-sized avatar
🇪🇪

Andris Reinman andris9

🇪🇪
View GitHub Profile
/*
* Strip unwanted HTML tags and unwanted attributes
*/
limitHTML = function(html){
var re = new RegExp("^(a|b|blockquote|code|del|dd|dl|dt|em|h1|h2|h3||i|img|li|ol|p|pre|sup|sub|strong|strike|ul|br|hr)$"),
attribs = {
"img": new RegExp("^(src|width|height|alt|title)$"),
"a": new RegExp("^(href|title)$")
}
var EventEmitter = require('events').EventEmitter,
sys = require('sys');
this.Base64Stream = function(){
EventEmitter.call(this);
this.current = "";
}
sys.inherits(this.Base64Stream, EventEmitter);
@andris9
andris9 / test.js
Created April 28, 2011 15:17
send 10 e-mail messages at once
var
nodemailer = require('./extlib/andris9-Nodemailer-1034ae8/lib/mail');
if(true){
/*
nodemailer.SMTP = {
host: "localhost",
port: 25,
use_authentication: false,
}*/
@andris9
andris9 / nodejs_idcard.js
Created August 8, 2011 19:51
Node.js + ID kaart
var https = require('https'),
fs = require('fs'),
utillib = require('util');
var options = {
key: fs.readFileSync('private_key.pem'),
cert: fs.readFileSync('certificate.pem'),
ca: [
fs.readFileSync('ESTEID-SK 2007.PEM.cer'),
fs.readFileSync('ESTEID-SK.PEM.cer'),
@andris9
andris9 / simpleajax.js
Created January 5, 2012 10:02
Extremely simple AJAX call
function SimpleAJAX(url, body, callback){
if(!callback && typeof body=="function"){
callback = body;
body = undefined;
}
var http = new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP");
http.open(body?'post':'get', url);
@andris9
andris9 / cookbook.md
Created February 20, 2012 08:44
node cookbook

Node Cookbook

Kill child process when parent quits

Source SO

Reuiqures: node-ffi

// handle parent death

(function(){

@andris9
andris9 / git-cache-meta.sh
Created March 5, 2012 13:15
git-cache-meta
#!/bin/sh -e
#git-cache-meta -- simple file meta data caching and applying.
#Simpler than etckeeper, metastore, setgitperms, etc.
#from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
#modified by n1k
# - save all files metadata not only from other users
# - save numeric uid and gid
# 2012-03-05 - added filetime, andris9
DKIM
openssl genrsa -out key.txt 768
openssl rsa -in key.txt -out pub.txt -pubout -outform PEM
DNS
namespace._domainkey.node.ee TXT v=DKIM1;k=rsa;t=s;p=PUBKEY
@andris9
andris9 / tcpproxy.js
Created April 18, 2012 09:31
TCP proxy
var net = require('net'),
tls = require('tls'),
fs = require("fs");
var targetHost = "imap.gmail.com",
targetPort = "993",
targetSecure = true,
logfile = "log.txt",
proxyPort = 143;
@andris9
andris9 / email.md
Created October 29, 2012 08:34
E-mail article for NKO

Sending E-Mail messages from Node.js — Andris Reinman

tl;dr — How to send an e-mail using Nodemailer

Install Nodemailer

> npm install nodemailer

Include the module in your script and create a reusable transport object