Skip to content

Instantly share code, notes, and snippets.

@plugnburn
plugnburn / README.md
Last active Aug 29, 2015
AsgardJS Microframework
View README.md

AsgardJS microframework

Overview

AsgardJS is a less-than-1K (1015 bytes) microframework to make routine HTML5 tasks easier. It includes DOM manipulation, client-side URL hash routing, a basic string templating engine and AJAX calls. Use with HTML5 doctype only!

P.S. Please keep in mind AsgardJS is oriented for the modern Web, so neither it does include some things that are already implemented as native browser solutions (e.g. it has no class manipulation because there's no need to reinvent classList), nor it has any obsolete browser support. Estimated support for browser versions: Chrome 5+, IE 10+ (9 may work), Firefox 4+, Opera 12+, Safari 5+, Android Browser 2.2+. DOM manipulation

  • Element._(selector) - check if the element matches the selector
@plugnburn
plugnburn / asgard-ext.js
Created Jul 9, 2014
AsgardJS extensions
View asgard-ext.js
//AsgardJS extensions
//__.loadTemplate(templateurl,selector,dataToRender)
__.loadTemplate=function(u,s,d){___(u,function(r){__(s,function(e){e.innerHTML=r._(d)})})}
//__.R(function) - shortcut for requestAnimationFrame cross-browser call
eval("__.R=window.rXwebkitRXmozRXoRXFunction('c','setTimeout(c,15)')".replace(/X/g,"equestAnimationFrame||window."));
//__.beat(formula,duration) - get 8Khz WAV file data: URL calculated according to a bytebeat formula.
__.beat=function(b,e,a,t){return(a="data")+":audio/wav;base64,UklGRl9fX19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgA"+btoa(eval("with(Math)for(t=0;++t<e*8e3;)a+=String.fromCharCode(255&("+b+"))"))}
@plugnburn
plugnburn / README.md
Last active Aug 29, 2015
Micromark engine
View README.md

Micromark: probably the smallest JS framework to create your own text markup languages

Overview

Have you ever dreamed of creating your own simple text markup language without all the overhead of existing parsers? Now it is possible thanks to this tiny function. Define your own rules for substituting your own character tags with HTML markup and pass them to Micromark along with your text, and it will return ready HTML code. How to use the engine

Call the function like this:

outHTML = micromark(your_string, rules_object);
@plugnburn
plugnburn / README.md
Last active Aug 29, 2015
Bro.js - Smallest (under 4K) yet very functional browser written for Gjs and WebkitGTK
View README.md

Description and manual coming soon

@plugnburn
plugnburn / README.md
Last active Aug 29, 2015
DualWarp - a universal bootloader for data:URIs and external scripts to be usable in redirectable URLs
View README.md

Overview

DualWarp is a simple 134-byte bootloader for URIs and external scripts. It was created for users who want their data: URIs and external script to be allowed for shortening and cloaked execution. You just host this single HTML file and then pass whatever you want (data: URI or external Javascript link) into the URL hash.

Usage

Note that when you call external script, it may be served as any MIME-type, so hacks like [Giffer] (https://gist.github.com/plugnburn/3364bc56ecc820534143) will also work when your JS is embedded into a GIF and uploaded to an image hosting.

@plugnburn
plugnburn / README.md
Last active Aug 29, 2015
LCore: a tiny Lisp-like interpreter core
View README.md

Overview

LCore is a simple interpreter that supports Lisp syntax for your own pre-defined operations. With its help, you can build your own Lisp-like language on top of JavaScript. How to use

First, define your operation list. Operation list is a JS object where the keys are operation names and the values are the functions that implement these operations. Every function can take the list of arguments (i.e. a single array) as its first parameter and then return whatever it needs to return. Every operation is defined this way.

Example (you can find more complete and usable demo example in the demo-ops.js file of this gist):

ops={
@plugnburn
plugnburn / zw.js
Last active Aug 29, 2015
Zero-Width encoder/decoder with autodetection feature in 400 bytes
View zw.js
ZW={enc:function(s){return unescape(encodeURIComponent(s)).split("").map(function(c){return("00000000"+c.charCodeAt(0).toString(2)).substr(-8)}).join("").replace(/0/g,"\u200b").replace(/1/g,"\u200c")},dec:function(s){return(s=s.match(/[\u200b\u200c]{8}/g))&&decodeURIComponent(escape(s.map(function(c){return String.fromCharCode(parseInt(c.replace(/\u200b/g,0).replace(/\u200c/g,1),2))}).join("")))}}
@plugnburn
plugnburn / watchcoder.sh
Last active Aug 29, 2015
WatchCoder - encode any number from 0 to 5183999 to the values you can store in your Casio electronic watch, decode the stored values back into number
View watchcoder.sh
#!/bin/bash
# The WatchCoder method guarantees to encode an unsigned 22-bit (or signed 21-bit converted to unsigned)
# integer into the values present in any electronic Casio watch: an alarm setting and 1-hour stopwatch
# Maximal theoretically encodable unsigned value is 5183999
case "$1" in
num2watch)
[ -z "$2" ] && echo "Specify the number to encode" && exit 1
NUM=$2
SWDABS=$(($NUM / 1440))
ALMABS=$(($NUM % 1440))
@plugnburn
plugnburn / README.md
Last active Aug 29, 2015
SMSPP: Short Message Security
View README.md

SMSPP: Short Message Security

Overview

SMSPP (stands for Short Message Security - Pencil and Paper) is a simple, pencil-and-paper based protocol to exchange very short encrypted messages via commonly available communication channels with a limited character set (such as SMS, hence the name).

SMSPP Workflow

@plugnburn
plugnburn / ringamerica.sh
Last active Aug 29, 2015
Free ring on any US/Canada number (no call, just ring) shell script
View ringamerica.sh
#!/bin/bash
ERRTEXT='There was a problem with sending the call'
PRENUM=$(echo -n "$1"|sed -re 's/[^0-9]+//g'|tail -c 10)
AREACODE=$(echo -n "$PRENUM"|head -c 3)
LOCALNUM=$(echo -n "$PRENUM"|tail -c 7)
rawresp=$(curl http://www.wheresmycellphone.com/ -d "noArea=$AREACODE&noNumb=$LOCALNUM&noWhen=0" 2>&1)
result=$(echo "$rawresp"|grep "$ERRTEXT")
[ -z "$result" ] && echo "Ring request sent" || echo "Line busy, try again later"
[ -z "$result" ] && exit 0 || exit 1