Skip to content

Instantly share code, notes, and snippets.

@rodzyn
rodzyn / async-experiments.js
Last active November 10, 2018 16:48
Async & Generators
//Async/await implementation via generators
function continueFlow(value) {
generator.next(value);
}
function* createFlow() {
console.log('First');
const apiResponse = yield fetch('https://api.github.com/users/github');
console.log('Third');
@rodzyn
rodzyn / gist:1094864
Created July 20, 2011 12:26
Node.js - pcap - blog post
<h2>Currently available:</h2>
<div class="applicaker_photo">
<% for (member in applicakers) { %>
<!-- Comparing the current time with the last time we captured his packets -->
<% if (((current_time - applicakers[member].time)/60000) < 15) { %>
<img height="125" src="<%= applicakers[member].photo %>" width="250" />
<% } %>
<% } %>
</div>
@rodzyn
rodzyn / webserver.js
Created July 20, 2011 12:20
Node.js - node_pcap - capturing packets
var http = require('http'),
sys = require("sys"),
pcap = require("pcap"),
ejs = require("ejs"),
fs = require('fs'),
pcap_session;
//It's just a simple code. For a long term solution you should use db storage.
var team = {
rodzyn: {
@rodzyn
rodzyn / gist:1092168
Created July 19, 2011 12:42
Aspect-oriented programming - JS
var aspect = {
checkConditions: function (obj) {
//Object existance checking
if (obj === null || typeof(obj) === "undefined") {
obj = function(){ return this; }.call();
}
//Type checking
if (typeof(obj) !== "object" ) {
throw new TypeError();
@rodzyn
rodzyn / gist:1089046
Created July 18, 2011 09:49
Aspect-oriented programming - JS - blog example
//Fake logging function - aspect function
var loggingFunction = function() { /* implementation */ }
//Object with method
var foo = {
bar: function() { /* implementation */ }
}
//Aspect wrapper
var aspect = {