Skip to content

Instantly share code, notes, and snippets.

View audinue's full-sized avatar

Audi Nugraha audinue

  • Surabaya, Jawa Timur, Indonesia
View GitHub Profile
@audinue
audinue / repeat.js
Created December 26, 2014 16:49
Repeat certain element in HTML.
/*
Usage:
<script src="repeat.js"></script>
Example:
<ul>
<li repeat="3">Hello World!</li>
</ul>
will produce:
<ul>
<li repeat="3">Hello World!</li>
@audinue
audinue / tpl.php
Created January 13, 2015 17:10
Simple utility for template designers.
<?php
define('EXTENDS_PATTERN', '/\{extends ([a-z0-9_\/-]+)\}/');
define('BLOCK_PATTERN', '/\{block ([a-z0-9_-]+)\}([^\{]*)\{\/block\}/');
define('INCLUDE_PATTERN', '/\{include ([a-z0-9_\/-]+)\}/');
function tpl_compile($file) {
if(!is_file($file)) {
throw new Exception('File "' . $file . '" is not found.');
}
@audinue
audinue / SimpleTemplate.php
Created January 28, 2015 06:44
SimpleTemplate
<?php
class SimpleTemplate {
function renderString($string, $args = NULL) {
if(is_array($args)) {
$this->validateArgs($args);
extract($args);
}
eval('?>' . $this->parseString($string));
@audinue
audinue / FullTypeName.bas
Last active August 29, 2015 14:17
Get full type name from an object.
' Require TypeLib Information
' Returns "Project1.Class1" instead of only "Class1"
Public Function FullTypeName(Object As Object) As String
FullTypeName = TLIApplication.InterfaceInfoFromObject(Object).Parent.Name & "." & TypeName(Object)
End Function
@audinue
audinue / MouseWheel.as
Created May 4, 2015 15:56
Mouse Wheel Zoom
import flash.events.MouseEvent;
stage.addEventListener(MouseEvent.MOUSE_WHEEL, mouseWheel);
var scale:Number = 1;
function mouseWheel(e:MouseEvent):void {
scale = e.delta > 0 ? scale + .5:scale - .5;
image.scaleX = image.scaleY = scale;
image.x = mouseX - e.localX * image.scaleX;
var x = scroll.x;
var y = scroll.y;
var minX = undefined, maxX = undefined;
var minY = undefined, maxY = undefined;
if(x < 0) {
while(x < paisley.width) {
if(x > -paisley.width) {
if(minX === undefined) {
minX = x;
}
var minX = 0, maxX = 0;
var minY = 0, maxY = 0;
if(scroll.x > 0) {
maxX = scroll.x % paisley.width;
minX = maxX > 0 ? -paisley.width + maxX : (maxX < 0 ? -paisley.width + maxX : 0);
} else if(scroll.x < 0) {
minX = scroll.x % paisley.width;
minX = minX == 0 ? 0 : minX;
maxX = minX + canvas.width;
maxX = maxX >= canvas.width ? minX : maxX;
@audinue
audinue / DragMoveNativeWindowManually.as
Created February 3, 2016 02:31
Drag move NativeWindow manually in AIR (doesn't use NativeWindow.startMove()).
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.display.NativeWindow;
var down:Boolean = false;
var offset:Point = new Point();
stage.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void {
down = true;
var p:Point = new Point(e.stageX, e.stageY);
<?php
class SDO {
private $pdo;
function __construct(PDO $pdo) {
$this->pdo = $pdo;
}
var div = document.createElement('div');
var wraps = {
'option': [1, '<select multiple="multiple">'],
'legend': [1, '<fieldset>'],
'thead' : [1, '<table>'],
'tr' : [2, '<table><tbody>'],
'td' : [3, '<table><tbody><tr>'],
'col' : [2, '<table><tbody></tbody><colgroup>'],