This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// my for-each thing | |
function forEeach(array, action) { | |
try { | |
var len = array.length; | |
for (var i = 0; i < len; i++) | |
action(array[i]); | |
} catch (e) { | |
throw e; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create event | |
var minE = new CustomEvent("yourEventName", { | |
detail: { | |
"key": value | |
}, | |
bubbles: true, | |
cancelable: true | |
}); | |
//add handler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Converts canvas to an image | |
function Cnvs2Img(canvas) { | |
var image = new Image(); | |
image.src = canvas.toDataURL("image/png"); | |
return image; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Converts image to canvas; returns new canvas element | |
function Img2Cnvs(image) { | |
var canvas = document.createElement("canvas"); | |
canvas.width = image.width; | |
canvas.height = image.height; | |
canvas.getContext("2d").drawImage(image, 0, 0); | |
return canvas; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Changes XML to JSON | |
function xmlToJson(xml) { | |
// Create the return object | |
var obj = {}; | |
if (xml.nodeType == 1) { // element | |
// do attributes | |
if (xml.attributes.length > 0) { | |
obj["@attributes"] = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function clone(src) { | |
function mixem(src, dst, fnc) { | |
var i, em, nm, j = {}; | |
for(nm in src){ | |
j = src[nm]; | |
if(!(nm in dst) || (dst[nm] !== j && (!(nm in em) || em[nm] !== j))){ | |
dst[nm] = fnc ? fnc(s) : j; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- clock widget exmple --> | |
<!DOCTYPE html> | |
<html> | |
<head runat="server"> | |
<meta charset="utf-8"> | |
<title></title> | |
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fileName = $_FILES['afile']['name']; | |
$fileType = $_FILES['afile']['type']; | |
$fileContent = file_get_contents($_FILES['afile']['tmp_name']); | |
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent); | |
$json = json_encode(array( | |
'name' => $fileName, | |
'type' => $fileType, | |
'dataUrl' => $dataUrl, |
NewerOlder