Skip to content

Instantly share code, notes, and snippets.

var TemplateEngine = function(html, options) {
var re = /<%([^%>]+)?%>/g,
reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,
code = 'var r=[];\n',
cursor = 0,
add = function(line, js) {
js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') :
(code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : '');
return add;
};
@aheinze
aheinze / password_hash (PHP)
Created August 21, 2013 12:39
A Compatibility library with PHP 5.5's simplified password hashing API.
<?php
/**
* A Compatibility library with PHP 5.5's simplified password hashing API.
*
* @author Anthony Ferrara <ircmaxell@php.net>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @copyright 2012 The Authors
*/
if (!defined('PASSWORD_DEFAULT')) {
@aheinze
aheinze / gist:263225e99ca18e2dc2f636d49e7f6357
Last active July 13, 2016 07:45
Get css variable (cross browser)
/**
<style>
.var-test:before {
content: 'hello';
}
</style>
@aheinze
aheinze / fuzzy-search.php
Last active August 20, 2018 07:44
Fuzzy Search function - returning score
<?php
function fuzzy_search($search, $text, $distance = 3){
$needles = explode(' ', mb_strtolower($search, 'UTF-8'));
$tokens = explode(' ', mb_strtolower($text, 'UTF-8'));
$score = 0;
$levenshtein_utf8 = function ($s1, $s2) {
$map = [];
http://compose.mail.yahoo.com/?to={email_address}&subject={title}&body={url}
http://digg.com/submit?url={url}
http://pinterest.com/pin/create/link/?url={url}
http://service.weibo.com/share/share.php?url={url}&appkey=&title={title}&pic=&ralateUid=
http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={url}
http://surfingbird.ru/share?url={url}&description={text}&screenshot={image}&title={title}
http://vk.com/share.php?url={url}&title={title}&comment={text}
http://widget.renren.com/dialog/share?resourceUrl={url}&srcUrl={url}&title={title}&description={text}
http://www.addthis.com/bookmark.php?url={url}
http://www.douban.com/recommend/?url={url}&title={title}
@aheinze
aheinze / gist:02db57da725cf7ba4047
Last active October 30, 2022 07:30
letterAvatar - create Letter avatar based on name initials
/*
* LetterAvatar
*
* Create Letter avatar based on Initials -
* based on https://gist.github.com/leecrossley/6027780
*/
(function(w, d){
function LetterAvatar (name, size) {