Skip to content

Instantly share code, notes, and snippets.

View tlkahn's full-sized avatar
🥫

JG tlkahn

🥫
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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:59150cb4e062a8e5c29d
Created December 20, 2015 00:43
space lorem ipsum
/* Lorem Ipsum Generator
* (CC-BY) Fredrik Bridell <[email protected]> 2009
* Version 0.21 - multilingual
* Released under a Creative Commons Attribution License
*
* You are welcome to use, share, modify, print, frame, or do whatever you like with this
* software, including commercial use. My only request is that you tell the world where you found it.
*
* One way is to include the phrase:
* "Using the The Lorem Ipsum Generator by Fredrik Bridell (http://bridell.com/loremipsum/)"
@tlkahn
tlkahn / gist:e301c33686f995940d32
Created December 18, 2015 06:39
ios tableview basic boilerplate
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *data;
@end