Skip to content

Instantly share code, notes, and snippets.

@pstjvn
pstjvn / README.md
Last active September 28, 2015 14:05
Control delegation pattern

Main idea: separate the business logic from the underlying dom structure and bind execution to structure separately.

Benefits:

  • changes to DOM structure can be logically separated and execute from business logic changes
  • business logic changes do not rely on DOM strcuture (stability of business logic)
  • binding can be executed in any technology or mix of technologies
  • tests can be implemented for important business logic more easily as it is not bound to DOM.
@pstjvn
pstjvn / jsre.txt
Created October 17, 2011 11:20
JS indent keystroked for Gedit
indent:
^.*\)\s?{$
unindent:
^\s*}$
keys
}
@pstjvn
pstjvn / cssbrowserselector.js
Created September 16, 2011 19:36
css browser selector (Raphael Lima)
function css_browser_selector(u) {
var ua = u.toLowerCase(),
is = function(t) {
return ua.indexOf(t) > -1
},
g = 'gecko',
w = 'webkit',
s = 'safari',
o = 'opera',
m = 'mobile',
@pstjvn
pstjvn / example.js
Created May 26, 2011 14:41
OOEventDispatcher example
(function() {
var BindKeyboard = new Class({
handleKeyboardInput: function(code) {
switch (code) {
case 37:
return 'left';
case 38:
return 'up';
case 39:
return 'right';
@pstjvn
pstjvn / App.js
Created May 7, 2011 12:33
Local music player app
window.addEvent('domready', function() {
//
// augment omni grid to allow finding the next song
//
omniGrid.implement({
findNext: function(randompos) {
if (randompos) {
ci = Math.floor(Math.random() * this.elements.length);
} else {
ci = this.getSelectedIndices()[0] + 1;
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example23-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
</head>
<body>
<div ng-app="myapp">
<div ng-controller="Main as m">
@pstjvn
pstjvn / example-controller.js
Last active August 29, 2015 14:26
Angular + message bus + external app
goog.provide('test.angular.MainController');
goog.require('goog.string');
goog.require('test.angular.Service');
/**
* Main controller.
*
@pstjvn
pstjvn / 2phaseraf.js
Last active August 29, 2015 14:25
2 phase RAF
(function(global) {
var tasks = [[], []];
var doubleBufferIndex = 0;
var requestFrame = false;
var taskId = 0;
var running = false;
function requestAnimationFrame_() {
if (requestFrame) return;
@pstjvn
pstjvn / dart name spacing
Created April 22, 2015 10:42
How I arrange items in class
PointerAgent.internal(): super.internal() {
_startPoint = new Point(0, 0);
_currentPoint = new Point(0, 0);
_lastPoint = new Point(0, 0);
_longPressDelay = new Delay(1500, _fireLongPress);
_raf = new AnimationFrame(mutate: (_) {_handleAnimationFrame(_);});
_initEventListeners();
}
AnimationFrame _raf;
@pstjvn
pstjvn / code.gs
Created July 19, 2014 16:33
GAS issue
function onOpen() {
var ui = SpreadsheetApp.getUi();
var utilities = ui.createMenu('Utilities');
utilities
.addItem('Open', 'openDialog')
.addToUi();
}