Skip to content

Instantly share code, notes, and snippets.

// Simple JavaScript Templating
// John Resig - https://johnresig.com/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@afahy
afahy / template.js
Created October 22, 2009 19:07
Resig's JS templating
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
@kristian76
kristian76 / micro-template-engine.js
Last active April 26, 2024 08:18
micro template engine
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we’re getting a template, or if we need to
// load the template – and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
@VSeryoga
VSeryoga / array_sort.php
Created April 12, 2017 08:55
Сортировка многомерного массива по 2 знчениям
<?
function sort_nested_arrays( $array, $args = array('votes' => 'desc') ){
usort( $array, function( $a, $b ) use ( $args ){
$res = 0;
$a = (object) $a;
$b = (object) $b;
foreach( $args as $k => $v ){
if( $a->$k == $b->$k ) continue;
@junpluse
junpluse / SwipeNavigationController.h
Last active April 26, 2024 08:15
Simple implementation for swipe-to-back/forward UINavigationController
#import <UIKit/UIKit.h>
@interface SwipeNavigationController : UINavigationController <UIGestureRecognizerDelegate>
@property (nonatomic, readonly) NSArray *poppedViewControllers;
- (void)clearPoppedViewControllers;
@property (nonatomic, readonly) UISwipeGestureRecognizer *leftSwipeGestureRecognizer;
@abbotto
abbotto / jss.js
Last active April 26, 2024 08:15
JavaScript StyleSheets
/**
* JSS
* Author: Jared Abbott
* Copyright 2015 Jared Abbott
* Distributed under the MIT license
*
* @param {Object}
*/
var _jss = function(jss, combinator) {
var _toString = Function.prototype.call.bind(Object.prototype.toString);
@abbotto
abbotto / xhrBinary.js
Last active April 26, 2024 08:13
Get binary data with XHR in most browsers including IE8+
/*!
* xhrBinary.js
* Author: Jared Abbott
* Copyright 2015 Jared Abbott
* Distributed under the MIT license
*/
var xhrBinary = function(url, fn) {
// RESOURCES
// http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html
@abbotto
abbotto / nano-template.js
Last active April 26, 2024 08:13
A templating solution implemented in JavaScript [207 bytes minified+gzipped]
// Author: Jared Abbott
// Created: December 2015
// License: MIT
var template = function(tpl, data) {
// Make sure the cache is available
var w = window;
w.tplCache = !w.tplCache ? {} : w.tplCache;
// Prepare and load the template
tpl = ('"' + tpl.replace(/\{\{(.*?)\}\}/g, '"+$1+"') + '"').split(/\'+ | + \'/);
@thirdj
thirdj / templating.js
Created December 9, 2013 08:56
// Simple JavaScript Templating // John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
@loadenmb
loadenmb / snippet-pwsh_xorhexbyte.ps1
Created October 19, 2019 18:41
powershell XOR encoder / decoder and hex / byte - byte / hex conversions
# powershell XOR encoder / decoder and hex / byte - byte / hex conversions
# usage: execute & see output
# xor encoder / decoder
function xor($bytes, $string) {
$newBytes = @();
for ($i = 0; $i -lt $bytes.Count; $i++) {
$newBytes += $bytes[$i] -bxor $string[$i % $string.Length];
}
return $newBytes;