Skip to content

Instantly share code, notes, and snippets.

@charleslukes
charleslukes / package.json
Last active April 26, 2024 08:13
Webpack Configuration for ESModule
{
"type": "module",
"dependencies": { },
"devDependencies": {
"webpack": "^5.87.0",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.1",
},
@abbotto
abbotto / xhrBinary.js
Last active April 26, 2024 08:13
Get binary data with XHR in most browsers including IE8+
/*!
* xhrBinary.js
* Author: Jared Abbott
* Copyright 2015 Jared Abbott
* Distributed under the MIT license
*/
var xhrBinary = function(url, fn) {
// RESOURCES
// http://mgran.blogspot.com/2006/08/downloading-binary-streams-with.html
@abbotto
abbotto / nano-template.js
Last active April 26, 2024 08:13
A templating solution implemented in JavaScript [207 bytes minified+gzipped]
// Author: Jared Abbott
// Created: December 2015
// License: MIT
var template = function(tpl, data) {
// Make sure the cache is available
var w = window;
w.tplCache = !w.tplCache ? {} : w.tplCache;
// Prepare and load the template
tpl = ('"' + tpl.replace(/\{\{(.*?)\}\}/g, '"+$1+"') + '"').split(/\'+ | + \'/);
@thirdj
thirdj / templating.js
Created December 9, 2013 08:56
// Simple JavaScript Templating // John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
@loadenmb
loadenmb / snippet-pwsh_xorhexbyte.ps1
Created October 19, 2019 18:41
powershell XOR encoder / decoder and hex / byte - byte / hex conversions
# powershell XOR encoder / decoder and hex / byte - byte / hex conversions
# usage: execute & see output
# xor encoder / decoder
function xor($bytes, $string) {
$newBytes = @();
for ($i = 0; $i -lt $bytes.Count; $i++) {
$newBytes += $bytes[$i] -bxor $string[$i % $string.Length];
}
return $newBytes;
(function() {
var cache = {};
this.tmpl = function tmpl(str, data) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :
@moresheth
moresheth / microtemplating.js
Created October 12, 2011 16:31
John Resig's MicroTemplating with Curly Braces
/*
This comes directly from John Resig's MicroTemplating, but with {%= %} instead of <%= %> for the dynamic sections.
http://ejohn.org/blog/javascript-micro-templating/
This lets you use just natural Javascript, along with whatever JS library you're using, and can be inside of a Rails erb template, or whatever.
Used with a template inside the HTML of the page:
<script type="text/html" id="user_tmpl">
@tanyuan
tanyuan / smart-caps-lock.md
Last active April 26, 2024 08:11
Smart Caps Lock: Remap Caps Lock to Control AND Escape

Smart Caps Lock: Remap to Control AND Escape (Linux, Mac, Windows)

Caps Lock 變成智慧的 Control 以及 Escape

  • 單獨輕按一下就是 Escape
  • 若按下時同時按著其他鍵,就會是 Control

這應該是 Vim 和 Emacs 的最佳解了!(Emacs? Bash 的快捷鍵就是 Emacs 系列的)

  • Send Escape if you tap Caps Lock alone.
@fliedonion
fliedonion / !GIST file list order - summary.md
Last active April 26, 2024 08:11
Understand GIST file list order.
Summary How to control (or Understand) your GIST page's files list order.
Notice not official documentation.
@BrianWill
BrianWill / Javascript - asynchronous code.md
Last active April 26, 2024 08:11
Using asynchronous API's using callbacks and Promises

In most programming languages, most functions are synchronous: a call to the function does all of its business in the same thread of execution. For functions meant to retrieve data, this means the data can be returned by calls to the function.

For an asynchronous function, a call to the function triggers business in some other thread, and that business (usually) does not complete until after the call returns. An asynchronous function that retrieves data via another thread cannot directly return the data to the caller because the data is not necessarily ready by the time the function returns.

In a sense, asynchronous functions are infectious: if a function foo calls an asynchronous function to conclude its business, then foo itself is asynchronous. Once you rely upon an asynchronous function to do your work, you cannot somehow remove the asynchronicity.

callbacks

When the business initiated by an asynchronous function completes, we may want to run some code in response, so the code run