Skip to content

Instantly share code, notes, and snippets.

Vesa Poikajärvi vesse

Block or report user

Report or block vesse

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vesse
vesse / checkout-api-hmac.js
Last active May 14, 2018
Checkout API HMAC example
View checkout-api-hmac.js
const crypto = require('crypto');
const ACCOUNT = '375917';
const SECRET = 'SAIPPUAKAUPPIAS';
const headers = {
'checkout-account': ACCOUNT,
'checkout-algorithm': 'sha256',
'checkout-method': 'POST'
};
@vesse
vesse / geoserver-setup.md
Last active Jan 24, 2017
GeoServer test setup
View geoserver-setup.md

US Counties on GeoServer

Just a test and a note to self.

Data

wget http://www2.census.gov/geo/tiger/GENZ2015/kml/cb_2015_us_county_500k.zip
unzip cb_2015_us_county_500k.zip
View app-test.js
var chai = require('chai'),
should = chai.should(),
expect = chai.expect(),
assert = chai.assert,
supertest = require('supertest-as-promised'),
api = supertest('http://localhost:3000');
describe('Pictures', function () {
it('should add a picture', function (done) {
api.post('/api/v1/pictures')
View appA.html
<!DOCTYPE html>
<html>
<head>
<script src='http://localhost:3000/socket.io/socket.io.js'></script>
<script>
var socket = io.connect('http://localhost:3000/nsa');
socket.emit('request', {
msg : 'appA user is requesting something'
});
socket.on('incoming-request', function(data) {
View server.js
var express = require('express'),
bodyParser = require('body-parser'),
passport = require('passport'),
LocalStrategy = require('passport-local').Strategy;
var app = express();
passport.use(new LocalStrategy(function (username, password, cb) {
cb(null, false, {message: 'This can never succeed'});
}));
@vesse
vesse / sid.coffee
Last active Jul 5, 2018
Convert binary buffer object SID to string
View sid.coffee
# 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 Apr 2, 2018
Mongo binary UUID to Java legacy string and vice versa
View uuid.coffee
{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 Aug 29, 2019
Two Passport + JWT (JSON Web Token) examples
View express-jwt.js
//
// 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 Jun 2, 2019
stackoverflow#26403853
View login.jade
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 Oct 24, 2013
Basic HAProxy setup for nodejs app
View haproxy.con
global
daemon
maxconn 4096
user haproxy
group haproxy
defaults
log global
frontend http-in
You can’t perform that action at this time.