Skip to content

Instantly share code, notes, and snippets.

@plugnburn
plugnburn / democode.js
Last active Dec 25, 2015
Some democode routines (will be updated from time to time)
View democode.js
//bytebeat: beat(pattern,length)
beat=function(b,e,a,t){return(a="data")+":audio/wav;base64,UklGRl9fX19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgA"+btoa(eval("for(t=0;++t<e*8e3;)a+=String.fromCharCode(255&("+b+"))"))}
//bytebeat with math: beatm(pattern,length)
beatm=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+"))"))}
//konamicode: konami(callback)
konami=function(k,c){onkeyup=function(e){/113302022928$/.test(c+=[e.which-37])&&k()}}
//circle gesture detection: circgest(callback[, clockwiseflag])
//clockwiseflag: 1 - counterclockwise, 0 or absent - clockwise
circgest=function(f,a,v,i,c,o){c=v="";addEventListener("mousemove",function(e){o&&(i=2*(e.screenX>o.screenX)+(e.screenY>o.screenY),i^c&&(v+=i,c=i),(a?/3201$/:/2310$/).test(v)&&(f(),v=""));o=e},0)}
@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 / giffer.sh
Created Jul 10, 2014
Giffer - seamlessly embed JS into a GIF image to be usable both in <script> and <img> tags
View giffer.sh
#!/bin/bash
#Usage: giffer.sh input.gif input.js output.gif
(echo -n "GIF89a=/*";tail -c +10 $1;echo -n "*/0;$(<$2);")>$3
@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 / vmusic.sh
Last active Oct 3, 2017
VMusic - An advanced VK music finder/player in bash
View vmusic.sh
#!/bin/bash
PLAYER="mpg123 --utf8 --long-tag"
VMPID="/tmp/vmusic_mainpid"
PLAYERPID="/tmp/vmusic_playerpid"
VMTRACK="/tmp/vmusic_trackurl"
VMINFO="/tmp/vmusic_trackinfo"
SELFNAME="$0"
fetch() {
ACCESS_TOKEN='8426e7c42b7136646ac0c655ea0c09ad97bd80919a04a28d2e5a7860ab10862c3ac4805f27a75e096a589'
ENDPOINT="https://api.vk.com/method/audio.search"