Skip to content

Instantly share code, notes, and snippets.

View semmel's full-sized avatar

Matthias Seemann semmel

View GitHub Profile
@charlesdaniel
charlesdaniel / basic_auth_nodejs_test.js
Created January 27, 2012 02:53
Example of HTTP Basic Auth in NodeJS
var http = require('http');
var server = http.createServer(function(req, res) {
// console.log(req); // debug dump the request
// If they pass in a basic auth credential it'll be in a header called "Authorization" (note NodeJS lowercases the names of headers in its request object)
var auth = req.headers['authorization']; // auth is in base64(username:password) so we need to decode the base64
console.log("Authorization Header is: ", auth);
@mx4492
mx4492 / recursive-blocks.m
Last active April 13, 2022 16:21
Recursive Blocks in Objective C (under ARC)
#include <stdio.h>
/**
This only works if the block in question is called synchronously.
*/
void try0() {
typedef void(^RecursiveBlock)();
__block int i = 5;
@konstantint
konstantint / spawn.cpp
Created November 14, 2014 17:28
Example of communication with a subprocess via stdin/stdout
//
// Example of communication with a subprocess via stdin/stdout
// Author: Konstantin Tretyakov
// License: MIT
//
#include <ext/stdio_filebuf.h> // NB: Specific to libstdc++
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
@jimmydivvy
jimmydivvy / JavascriptIOMonadExample.js
Last active May 26, 2024 18:47
Simple IO Monad example in Javascript
class IO {
// We construct the IO type with a thunk/callback that returns the value when called
constructor( fn ){
this.fn = fn;
}
// IO doesn't do anything until we explicitly call it.
run(){
return this.fn();
@windoze
windoze / rx-asio.hpp
Created December 19, 2015 14:06
Boost.ASIO scheduler for RxCPP
#include "rxcpp/rx-scheduler.hpp"
// TODO: C++17 Networking TS
#ifdef WITHOUT_BOOST
// Standalone ASIO
#include <asio.hpp>
namespace asio_ns=::asio
namespace system_ns=::std
#else
// Boost.ASIO
@Avaq
Avaq / combinators.js
Last active June 22, 2024 19:27
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@harto
harto / before.js
Created April 20, 2016 17:33
Mocha before() & beforeEach() execution order with nested describe()
'use strict';
describe('mocha before hooks', function () {
before(() => console.log('*** top-level before()'));
beforeEach(() => console.log('*** top-level beforeEach()'));
describe('nesting', function () {
before(() => console.log('*** nested before()'));
beforeEach(() => console.log('*** nested beforeEach()'));
it('is a nested spec', () => true);
});
@caligo-mentis
caligo-mentis / mocha-uncaught-exception.js
Created June 9, 2016 07:30
Test uncaught exception with mocha tests runner
var should = require('should');
describe('uncaught exception', function() {
describe('with interception', function() {
var listeners;
beforeEach(function() {
listeners = process.listeners('uncaughtException');
process.removeAllListeners('uncaughtException');
@dypsilon
dypsilon / reader.js
Last active April 28, 2024 08:50
Example usage of the reader monad.
/**
* This short program will encrypt the user password
* and insert a new record into a mock database.
*/
const Reader = require('fantasy-readers');
const R = require('ramda');
const crypto = require('crypto');
// our mock database
const database = [
@WebReflection
WebReflection / dom-libraries.md
Last active February 6, 2024 15:50
A recap of my FE / DOM related libraries

My FE/DOM Libraries

a gist to recap the current status, also available as library picker!

Minimalistic Libraries

do one thing only and do it well

  • µhtml (HTML/SVG auto-keyed and manual keyed render)
  • augmentor (hooks for anything)
  • wickedElements (custom elements without custom elements ... wait, what?)