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
char * buffer;
buffer = (char*) malloc (42);
// Do something with buffer
free (buffer);
@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
}
<?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);
import React from "react";
import DiscoverReleaseForm from "./releaseManager/DiscoverReleaseForm";
import EditReleaseForm from "./releaseManager/EditReleaseForm";
class ReleaseManager extends React.Component {
constructor(props) {
super(props);
this.state = {
var numbers = [12, 22, 45, 13, 66, 1, 100, 1, 210, 10, 11];
var max = 0;
for (var i = 0;i < numbers.length; i++){
console.log(`numbers.length is ${numbers.length}, i is ${i}, numbers at position ${i} is ${numbers[i]}`);
console.log(`Now we test if ${max} is lower than ${numbers[i]}`);
if(max < numbers[i]){
console.log(`I is lower, so now ${numbers[i]} is the new max.`);
max = numbers[i];
/**
* Simple userland heapdump generator using v8-profiler
* Usage: require('[path_to]/HeapDump').init('datadir')
*
* @module HeapDump
* @type {exports}
*/
var fs = require('fs');
var profiler = require('v8-profiler');