Skip to content

Instantly share code, notes, and snippets.

View subzey's full-sized avatar

Anton Khlynovskiy subzey

View GitHub Profile
@subzey
subzey / clamp.js
Created September 13, 2016 13:53
clamp.js
function clamp(min, max, mid){
if (min <= max) { // Sanity check
if (mid > max) {
// Also implied: mid is not NaN
return max;
}
if (mid < min) {
// Also implied: mid is not NaN
# Define has_cats as true
has_cats: [x]
# Same for has_dogs
has_dogs: [x]
# Define has_dinosaurs as false
has_dinosaurs: [_]
# Some expressions
Tested on http://javascript.info/tutorial/keyboard-events
# English layout
keydown keyCode=87 which=87 charCode=0 char=W
keypress keyCode=119 which=119 charCode=119 char=w
keyup keyCode=87 which=87 charCode=0 char=W
------------------------------
keydown keyCode=65 which=65 charCode=0 char=A
keypress keyCode=97 which=97 charCode=97 char=a
// Create regexp once
var reUnicode = /[\u0080-\uFFFF]/g;
// Create functor once
function _unicodeEscape(character) {
return '\\u' + ('000' + character.charCodeAt(0).toString(16)).slice(-4);
}
function escapeJSON(jsonStr) {
// This function only accepts valid JSON strings
@subzey
subzey / index.html
Created October 11, 2016 09:22
This small code chunk will make Firefox eat all the memory
<svg onload=write()>
* {
case: lowercase;
max-empty-lines: 4 !warning;
}
selector {
max-empty-lines: 1;
}
*::comma {
@subzey
subzey / .block
Last active December 23, 2016 16:45
Merry Christmas and Happy New 2017 Year!
licence: WTFPL
height: 540
scrolling: no
border: no
@subzey
subzey / index.html
Last active December 26, 2016 16:46
webpack-screensaver.js
<!DOCTYPE html>
<html>
<head>
<title>Webpack screensaver</title>
<style>
html, body {
background: #000;
color: #aaa;
margin: 0;
user-select: none;
@subzey
subzey / index.html
Created January 12, 2017 17:14
Unclosed CSS
<body>
<style>
@media all {
body {
background: url('data:image/gif;base64,\
R0lGODdhEAAQAKECAAAAAP8AAP///////ywAAAAAEAAQAAACGkyEqWi3z6CctNorALha2759IUaWJuRYjRoUADs=
@subzey
subzey / universal-pre-commit-linter.sh
Created February 10, 2017 17:32
Universal pre-commit linter
#!/bin/sh
git diff --staged --name-only |
sed -e "s/.*/\x1b[41;30mERR\!\x1b[0;1;31m &\x1b[22m: Неправильно, ёбаные волки\! Широкую на широкую\!\x1b[m/g"
false