Skip to content

Instantly share code, notes, and snippets.

View JokingChicken's full-sized avatar
🐔
Always working, just not on the things I should...

DanJ JokingChicken

🐔
Always working, just not on the things I should...
View GitHub Profile
@JokingChicken
JokingChicken / TrueColour.md
Created April 15, 2018 20:12 — forked from XVilka/TrueColour.md
True Colour (16 million colours) support in various terminal applications and terminals

Colours in terminal

It's a common confusion about terminal colours... Actually we have this:

  • plain ascii
  • ansi escape codes (16 colour codes with bold/italic and background)
  • 256 colour palette (216 colours + 16 ansi + 24 gray) (colors are 24bit)
  • 24bit true colour ("888" colours (aka 16 milion))
printf "\x1b[${bg};2;${red};${green};${blue}m\n"
@JokingChicken
JokingChicken / reloadatfilesave.js
Last active June 17, 2018 21:08
reload if there is a file saved node
//check if is production, if it is we won't initiate this
var production = process.env.NODE_ENV === 'production'
if(!production) {
// we use chokidar for file watching
var chokidar = require('chokidar')
var watcher = chokidar.watch('./dist')
watcher.on('ready', function() {
watcher.on('all', function() {
console.log("Clearing /dist/ module cache from server");
@JokingChicken
JokingChicken / stringifyjson.js
Last active June 17, 2018 21:00
stringify json to human readable JSON
// stringify with tabs inserted at each level
JSON.stringify(jsObj, null, "\t");
// stringify with 2 spaces at each level
JSON.stringify(jsObj, null, " ");
@JokingChicken
JokingChicken / annotated.js
Last active June 15, 2018 12:25 — forked from jed/LICENSE.txt
generate random UUIDs
function b(
a // placeholder
){
return a // if the placeholder was passed, return
? ( // a random number from 0 to 15
a ^ // unless b is 8,
Math.random() // in which case
* 16 // a random number from
>> a/4 // 8 to 11
).toString(16) // in hexadecimal
@JokingChicken
JokingChicken / Base64.js
Last active June 17, 2018 20:57
Base64 Encoding and Decoding in Node
//Here is how you encode normal text to base64 in Node.js:
var b = new Buffer('JavaScript');
var s = b.toString('base64');
// SmF2YVNjcmlwdA==
//And here is how you decode base64 encoded strings:
var b = new Buffer('SmF2YVNjcmlwdA==', 'base64')
var s = b.toString();
// JavaScript
@JokingChicken
JokingChicken / attribute from element.html
Last active June 17, 2018 20:56
get element with attribute
<script>
//find first element with "someAttr" attribute
document.querySelector('[someAttr]');
//find all elements with "someAttr" attribute
document.querySelectorAll('[someAttr]');
//so this is how you can get a specific element without using id or class
document.querySelector([attribute="value"])
@JokingChicken
JokingChicken / SHA-256.js
Last active February 17, 2019 13:01
SHA-256 implementation in JavaScript
/**
* SHA-256 hash function reference implementation.
*
* This is an annotated direct implementation of FIPS 180-4, without any optimisations.
* it is intended to aid understanding of the algorithm rather than for production use!!!
*
* While it could be used where performance is not critical, I would recommend using the ‘Web
* Cryptography API’ (developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest) for the browser,
* or the ‘crypto’ library (nodejs.org/api/crypto.html#crypto_class_hash) in Node.js.
*
@JokingChicken
JokingChicken / LINK deploy node production server
Last active June 17, 2018 20:54
Deploying to production node server
@JokingChicken
JokingChicken / LINK Nginx Load Balancing
Last active June 17, 2018 20:53
Set Up Nginx Load Balancing
@JokingChicken
JokingChicken / scrollheight element.html
Last active June 17, 2018 20:53
get the real scroll height of div
<script>
// calculate max scroll top position (go back to top once reached)
var maxScrollPosition = element.scrollHeight - element.clientHeight;
// example
element.scrollTop = maxScrollPosition;
</script>