Skip to content

Instantly share code, notes, and snippets.

View tehfreak's full-sized avatar

Michael F tehfreak

View GitHub Profile
@tehfreak
tehfreak / emitter.js
Created October 2, 2015 14:44 — forked from brentertz/emitter.js
Node.js: Extend a class to be an EventEmitter
var util = require('util'),
EventEmitter = require('events').EventEmitter;
var Server = function() {
var self = this;
this.on('custom_event', function() {
self.logSomething('custom_event');
});
// SICP 3.5.2: https://sarabander.github.io/sicp/html/3_002e5.xhtml#g_t3_002e5_002e2
// Node v0.10.31
var stream = require('stream');
var getPrimes = function (count) {
integers(2)
.pipe(primes())
.pipe(take(count))
@tehfreak
tehfreak / connect-query.js
Created November 9, 2014 05:14
connect-query
var urlParse= require('url').parse // http://nodejs.org/api/url.html#url_url_parse_urlstr_parsequerystring_slashesdenotehost
app.use(function (req, res, next) {
req.query= urlParse(req.url, true).query
next()
})
struct rBuffer {
unsigned char *buffer;
uint8_t head;
uint8_t tail;
uint8_t count;
};
struct rBuffer *newRingBuffer(uint8_t length) {
unsigned char *buffer= (unsigned char *)malloc(length);
static struct rBuffer temp= {buffer,0,0,0};
@tehfreak
tehfreak / index.js
Created January 11, 2013 15:36
Role-based access control (RBAC) — проверка прав доступа ролей к ресурсам
/*/
* Возвращает функцию проверки прав доступа ролей к ресурсам
*
* @param {Function} fn — пользовательская функция, необязательно
* @return {Function}
*/
var access= function access (fn) {
fn= fn || function () {
return access.check.apply(
access, arguments