Skip to content

Instantly share code, notes, and snippets.

@alex-leonhardt
alex-leonhardt / main.go
Last active Feb 13, 2021
golang text/template with a map[string]interface{} populated from mixed json data
View main.go
package main
import (
"encoding/json"
"os"
"reflect"
"text/template"
)
@Radiergummi
Radiergummi / Cryptor.php
Last active Dec 15, 2020
A PHP class to encrypt and decrypt strings using a static application secret. Input is converted to hex strings to enable easier handling
View Cryptor.php
<?php
namespace Vendor\Library;
use function bin2hex;
use function hex2bin;
use function openssl_decrypt;
use function openssl_encrypt;
use function random_bytes;
View Transliterate file names bash
#!/bin/bash
# Перекодирует рекурсивно в текущем каталоге имена
# файлов и каталогов в транслит.
#
# Источник: http://www.ubuntu.sumy.ua/2011/03/translit.html
shopt -s nullglob
for NAME in * ; do
TRS=`echo $NAME | sed "y/абвгдезийклмнопрстуфхцы/abvgdezijklmnoprstufxcy/"`
TRS=`echo $TRS | sed "y/АБВГДЕЗИЙКЛМНОПРСТУФХЦЫ/ABVGDEZIJKLMNOPRSTUFXCY/"`
@inso
inso / Nginx redirect to named location
Last active Mar 16, 2021 — forked from ilguzin/nginx_redirect_2named_location
NGINX: Redirect from current location into named location
View Nginx redirect to named location
# Solution 1
# Use only codes greater than 418, do not use common status codes 404, 402, 403, etc
location /location1 {
error_page 463 = @app; return 463;
}
# Solution 2 (drawbacks unknown)
location /location2 {
try_files /dev/null @app;
}
@jherax
jherax / clone.js
Last active May 30, 2020
Clones or extends an object (deep copy) supporting objects with circular references
View clone.js
/**
* @author
* David Rivera (jherax)
* https://github.com/jherax
*/
/* eslint-disable no-bitwise */
/** @private */
const toString = Object.prototype.toString;
@Vestride
Vestride / encoding-video.md
Last active May 7, 2021
Encoding video for the web
View encoding-video.md

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
View umd-module.js
; (function (global, define) { define('module-name', function (require, exports, module) {
// CommonJS style code here
/*!
* UMD/AMD/Global context Module Loader wrapper
* based off https://gist.github.com/tejacques/202a8f2d198ddd54a409
*
* This wrapper will try to use a module loader with the
* following priority:
*
@yuval-a
yuval-a / js-micro.js
Last active May 3, 2021
Javascript micro-optimizations
View js-micro.js
// Array literal (= []) is faster than Array constructor (new Array())
// http://jsperf.com/new-array-vs-literal/15
var array = [];
// Object literal (={}) is faster than Object constructor (new Object())
// http://jsperf.com/new-array-vs-literal/26
var obj = {};
// property === undefined is faster than hasOwnProperty(property)
// Note: don't use this in cases where 'undefined' is a possible value for your properties
@duzun
duzun / jq.fn.$each.js
Last active Aug 29, 2015
4-10 times faster jQuery.fn.each() replacement
View jq.fn.$each.js
/**
* 4-10 times faster .each replacement
* use it carefully, as it overrides jQuery context of element on each iteration
*
* function clb(DOM, idx, $DOM, DOM) {};
* $DOM == $(DOM), is the same object throughout iteration
*
*/
;(function (global) {
@duzun
duzun / async_css.html
Last active Aug 29, 2015
Easiest and most natural way to load CSS asynchronously without blocking HTML rendering! Tested on https://limitlesslane.com/ https://casadelux.ru/ and other projects by DUzun.ME
View async_css.html
<html>
<head>
<!-- The <script> switches rel="prefetch" to rel="stylesheet" at proper time, et voila, magic happens :-) -->
<link rel="prefetch" type="text/css" href="https://cdn.limitlesslane.com/css/mini/async_lib.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.limitlesslane.com/css/mini/lib.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.limitlesslane.com/css/mini/app.css" />
<link rel="prefetch" type="text/css" href="https://cdn.limitlesslane.com/css/mini/async_app.css" />
<script>
;(function(w,d){