Skip to content

Instantly share code, notes, and snippets.

View tlkahn's full-sized avatar
🥫

JG tlkahn

🥫
View GitHub Profile
@tlkahn
tlkahn / gist:1059a8279bb528d3ad92
Created December 23, 2015 21:32
recursive es6 generator
var gen = function *(count){
console.log("gen called: ", count);
if (count < 20)
yield count;
else
yield *gen(count/2);
}
var g = gen(100);
do {
var n = g.next();
@tlkahn
tlkahn / gist:4247dcf60008237902c9
Created December 23, 2015 21:54
es6 recursive generator
var gen = function *(count){
console.log("gen called: ", count);
if (count < 20)
yield count;
else
yield *gen(count/2);
}
var g = gen(100);
do {
var n = g.next();
@tlkahn
tlkahn / d3.js
Created December 24, 2015 06:14
set module return value as global
if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
@tlkahn
tlkahn / index.js
Created January 8, 2016 19:21
angularjs directive attr observe and scope watch difference
app.controller('MainCtrl', function($scope) {
$scope.clickedTimes = 0;
$scope.prop1 = 2+3;
// $scope.prop2 = 'scope_prop2';
// $scope.aNumber = 44;
// $scope.obj = { prop1: "obj_prop1"}
$scope.changeProperties = function() {
$scope.prop1.prop1 = 'scope_prop1_changed after ' + ($scope.clickedTimes++) + ' clicks';
@tlkahn
tlkahn / index.js
Created January 8, 2016 19:51
angular directive embed and multiple transclude
app.directive('outer', function(){
return {
restrict: 'E',
controllerAs: 'outer',
require: 'outer',
template: '<p>{{outer.hello}}<p ng-transclude="outerInner"></p><p ng-transclude></p></p>',
scope: true,
transclude: {
outerInner: 'inner'
},
@tlkahn
tlkahn / angular-multiple-transclusion.js
Created January 8, 2016 21:29
angular multiple transclusion with compatibility of amd and node module
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['angular'], factory);
} else if (typeof exports === 'object') {
factory(require('angular'));
} else {
factory(root.angular);
}
}(this, function (angular) {
'use strict';
@tlkahn
tlkahn / gist:b3d47566b2385f059f44
Created January 11, 2016 06:10
angularjs factor service provider
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
};
});
//factory style, more involved but more sophisticated
@tlkahn
tlkahn / vtable.cpp
Created May 17, 2016 19:29 — forked from netguy204/vtable.cpp
Monkey patching a C++ class by modifying its VTABLE.
#include <stdio.h>
#include <stdint.h>
class A {
public:
virtual void doThing() {
printf("I'm an A\n");
}
};
@tlkahn
tlkahn / test.mm
Created May 18, 2016 04:10 — forked from drodriguez/test.mm
Objective-C++ NSString wrapper example
// $ g++ -o test -framework Foundation -Wall test.mm
// $ ./test
// The string length is 12
// The string third char value is 108
// The string is Hello World!
#include <iostream>
#import <Foundation/Foundation.h>
class MyCppNSStringWrapper
@tlkahn
tlkahn / adt.c
Created June 17, 2016 22:21 — forked from hosaka/README.md
Abstract Data Type using opaque pointers in C
#include <stdio.h>
#include <stdlib.h>
#include "array_api.h"
// abstract array data type types
// opaque pointer:
// an ADT implementation hidden behind the interface that is abstract to
// the client, making it easier to maintain, apply changes and improve
// in this example the array_t data type provides a bunch of functins