Skip to content

Instantly share code, notes, and snippets.

View danielkhan's full-sized avatar

Daniel Khan danielkhan

  • Sentry
  • Linz / Austria
  • X @dkhan
View GitHub Profile
@danielkhan
danielkhan / node-example.js
Last active September 1, 2021 00:40
node.js module.exports and exports explained
function Person(name) {
this.name = name;
}
var john = new Person('John');
// implicit done by node.js:
// exports = module.exports
exports.myperson = john;
// test = require('./lib/test');
@danielkhan
danielkhan / gist:6259104
Last active December 21, 2015 05:48
Fixing gist-embedding in wordpress
.gist .line,
.gist .line-number {
font-size: 12px !important;
line-height: 20px !important;
margin-bottom: 0px !important;
}
.gist * {
margin-bottom: 0px;
}
@danielkhan
danielkhan / gist:6270343
Created August 19, 2013 15:22
banner with streaming video
import flash.events.MouseEvent;
var sUrl:String = "http://<VIDEO_URI>";
var metaObj:Object = new Object();
var connection:NetConnection = new NetConnection();
var stream:NetStream;
connection.connect(null);
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
@danielkhan
danielkhan / gist:7698131
Last active December 29, 2015 16:29
Sanitizing Json data in Scala Play
implicit val transformFormat: Reads[JsObject] = {
(__ \ 'situation).json.update(of[JsString].map {
case JsString(situation) => JsString(Sanitizer.toMarkDown(situation))
}) andThen
(__ \ 'solution).json.update(of[JsString].map {
case JsString(solution) => JsString(Sanitizer.toMarkDown(solution))
}) andThen
(__ \ 'name).json.update(of[JsString].map {
case JsString(raw) => JsString(Sanitizer.toText(raw))
}) andThen
@danielkhan
danielkhan / gist:7770495
Created December 3, 2013 14:57
Json, case-classes and transformations in scala
package models
import _root_.utils.Sanitizer
import reactivemongo.bson._
import play.modules.reactivemongo.json.BSONFormats._
import play.api.libs.json._
import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._
import play.api.libs.json.JsString
import scala.Some
for {
res <- collection.update(Json.obj("slug" -> idea_slug, "user_id" -> Json.obj("$ne" -> vote.user_id)),
Json.obj("$addToSet" -> Json.obj(addType -> vote),
"$pull" -> Json.obj(removeType -> Json.obj("user_id" -> vote.user_id)),
"$addToSet" -> Json.obj("metrics.attachedUsers" -> vote.user_id))
, getLastError, false)
idea <- findOne(Json.obj("slug" -> idea_slug))
} yield {
idea
}
@danielkhan
danielkhan / AngularRequire.js
Last active August 29, 2015 13:56
This refers to the tutorial at: http://www.startersquad.com/blog/angularjs-requirejs/ and the problems getting the routingProvider $routeProvider working which results in "Unknown provider: $routeProvider".
// 1. you may need to download angular-routes separately - I got it along with the angular webjar
// 2. add path and shim config
// require config
requirejs.config({
shim: {
"app": ["angular"],
"angular-route": ["angular"] // !!!
@danielkhan
danielkhan / saml.js
Last active September 4, 2019 16:10
This is a hacked together version of passport-samls saml parser that supports shibboleth
var zlib = require('zlib');
var xml2js = require('xml2js');
var xmlCrypto = require('xml-crypto');
var crypto = require('crypto');
var xmldom = require('xmldom');
var querystring = require('querystring');
var moment = require('moment');
var xmlenc = require('xml-encryption');
var xpath = require('xpath');
<?php
// Connect to mySQL (*blocking*)
$link = mysqli_connect("localhost", "user", "password", "test");
// Run a query and store result object (*blocking*)
if($result = mysqli_query($link, "SELECT * FROM Person")) {
// Fetch data from phps internal buffer into $data
$data = mysqli_fetch_all($result);
// Require nodes http module
var http = require('http');
// Require a third party mysql module (use "npm install mysql" to install it)
var mysql = require('mysql');
// Create a connection pool
var pool = mysql.createPool({
host: 'localhost',
user: 'username',