Skip to content

Instantly share code, notes, and snippets.

View vesse's full-sized avatar

Vesa Poikajärvi vesse

View GitHub Profile
@vesse
vesse / sid.coffee
Last active July 5, 2018 23:48
Convert binary buffer object SID to string
# Convert binary encoded object SID to a string
# (eg. S-1-5-21-1004336348-1177238915-682003330-512)
#
# SID format: https://technet.microsoft.com/en-us/library/cc962011.aspx
#
# ldapjs `searchEntry` has attribute `raw` that holds the raw
# values, including the `objectSid` buffer when one exists. Pass that
# buffer to get the string representation that can then be easily
# used in LDAP search filters, for example.
#
@vesse
vesse / uuid.coffee
Last active April 2, 2018 19:38
Mongo binary UUID to Java legacy string and vice versa
{Binary} = require 'mongodb'
# Put together following https://github.com/mongodb/mongo-csharp-driver/blob/master/uuidhelpers.js
module.exports.toJUUID = toJUUID = (binId) ->
return "" unless binId?.buffer?
hex = binId.buffer.toString 'hex'
msb = hex.substr(0, 16)
lsb = hex.substr(16, 16)
msb = msb.substr(14, 2) + msb.substr(12, 2) + msb.substr(10, 2) + msb.substr(8, 2) + msb.substr(6, 2) + msb.substr(4, 2) + msb.substr(2, 2) + msb.substr(0, 2)
lsb = lsb.substr(14, 2) + lsb.substr(12, 2) + lsb.substr(10, 2) + lsb.substr(8, 2) + lsb.substr(6, 2) + lsb.substr(4, 2) + lsb.substr(2, 2) + lsb.substr(0, 2)
@vesse
vesse / express-jwt.js
Last active April 11, 2023 16:43
Two Passport + JWT (JSON Web Token) examples
//
// Implementation using express-jwt middle
//
var express = require('express'),
ejwt = require('express-jwt'),
jwt = require('jsonwebtoken'),
passport = require('passport'),
bodyParser = require('body-parser'),
LocalStrategy = require('passport-local').Strategy,
BearerStrategy = require('passport-http-bearer').Strategy;
@vesse
vesse / login.jade
Last active May 24, 2023 15:41
stackoverflow#26403853
doctype html5
html
head
title Test Page
body
.error #{message}
form(action='/login' method='POST')
label Email
input(type='email' name='email')
@vesse
vesse / haproxy.con
Created October 24, 2013 10:30
Basic HAProxy setup for nodejs app
global
daemon
maxconn 4096
user haproxy
group haproxy
defaults
log global
frontend http-in
@vesse
vesse / package.json
Created January 20, 2012 11:17
Stream live web cam video using Node.js and Gstreamer
{
"name": "streamingtest",
"version": "0.0.1",
"engines": {
"node": ">=0.6.0"
},
"dependencies": {
"express": "2.5.x",
"coffee-script": "1.2.x"
},