Skip to content

Instantly share code, notes, and snippets.

@friedemannsommer
friedemannsommer / google-cloud-pubsub.d.ts
Last active Jun 12, 2017
declaration file for Google Cloud PubSub
View google-cloud-pubsub.d.ts
declare module '@google-cloud/pubsub' {
import stream from 'stream'
import events from 'events'
interface ConfigurationObject extends Object {
projectId?: string
keyFilename?: string
email?: string
credentials?: CredentialsObject
autoRetry?: boolean
@friedemannsommer
friedemannsommer / merge-sort.js
Created Apr 3, 2017
Javascript merge sort implementation
View merge-sort.js
/* usage example */
console.log(
mergeSort(
[1, 8, 6, 8, 6, 4, 2, 10, 89, 5456, 55],
(a, b) => {
if (a > b) {
return -1
} else if (a < b) {
return 1
}
@friedemannsommer
friedemannsommer / server.js
Last active Dec 15, 2016
dependency free node file server (only for debugging purpose)
View server.js
const http = require('http')
const path = require('path')
const url = require('url')
const fs = require('fs')
const port = 8080
const mimeTypes = {
'.html': 'text/html',
'.js': 'application/javascript',
'.css': 'text/css',
View font-color.js
/**
* @url http://stackoverflow.com/questions/1855884/determine-font-color-based-on-background-color
* @url http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
**/
function perceptiveLuminance(color) {
return 1 - (0.299 * color.r + 0.587 * color.g + 0.114 * color.b) / 255
}
function getFontColor(backgroundColor) {
if (perceptiveLuminance(backgroundColor) < 0.5) {
@friedemannsommer
friedemannsommer / hhvm.conf
Last active Nov 27, 2016
Takes care about installing NGINX, NGINX-RTMP, NGINX-Pagespeed, LibreSSL, PHP, Composer, Laravel, Symfony, Node, NVM, OhMyZSH
View hhvm.conf
; php options
pid = /var/run/hhvm/pid
; hhvm specific
hhvm.server.file_socket = /var/run/hhvm/hhvm.sock
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.server.user = www-data
View compile-php7.sh
#!/bin/bash
# Some help from the various places like these.
# http://www.zimuel.it/install-php-7/
# http://www.hashbangcode.com/blog/compiling-and-installing-php7-ubuntu
# https://gist.github.com/m1st0/1c41b8d0eb42169ce71a
sudo apt-get update
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password development'
View functionName.js
function getFunctionName(fn) {
if (typeof fn.name === 'string') {
return fn.name;
}
var fnString = fn.toString();
var firstBracket = fnString.indexOf('(');
return fnString.substr(9, (firstBracket - 9));
}
View error.js
function stacktrace() {
var stack;
function trace(fn) {
return (typeof fn !== 'function')
? []
: trace(fn.caller).concat([fn.toString().split('(')[0].substring(9)]);
}
try {
View bind.js
function bind(fn, context) {
var givenArguments = [];
for (var _i = 2; _i < arguments.length; _i++) {
givenArguments[_i - 2] = arguments[_i];
}
if (typeof Function.prototype.bind == "function") {
return Function.prototype.bind.apply(fn, Array.prototype.concat.apply([context], givenArguments));
}
View stacktrace.js
function stacktrace() {
var stack;
function trace(fn) {
return (typeof fn !== 'function')
? []
: trace(fn.caller).concat([fn.toString().split('(')[0].substring(9)]);
}
try {