Skip to content

Instantly share code, notes, and snippets.

Avatar

Dimitri Witkowski antelle

View GitHub Profile
@antelle
antelle / openssl.sh
Created Sep 6, 2019
OpenSSL file encrypt/decrypt
View openssl.sh
# encrypt file.txt to file.enc using 256-bit AES in CBC mode
openssl enc -aes-256-cbc -salt -in file.txt -out file.enc
# the same, only the output is base64 encoded for, e.g., e-mail
openssl enc -aes-256-cbc -a -salt -in file.txt -out file.enc
# decrypt binary file.enc
openssl enc -d -aes-256-cbc -in file.enc -out file.txt
# decrypt base64-encoded version
@antelle
antelle / flush_dns_cache.sh
Created Sep 6, 2019
Flush DNS cache on macOS
View flush_dns_cache.sh
sudo killall -HUP mDNSResponder
@antelle
antelle / ram_disk.sh
Created Sep 6, 2019
Create a RAM disk on macOS
View ram_disk.sh
# 42 = desired disk size in megabytes
diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://$((42*2048))`
@antelle
antelle / server.js
Created Feb 10, 2019
Simple web server with node.js
View server.js
const http = require('http');
const path = require('path');
const fs = require('fs');
const port = 8080;
const server = http.createServer((req, resp) => {
const filePathPart = req.url.substr(1) || 'index.html';
const filePath = path.resolve(__dirname, filePathPart);
if (!filePath.startsWith(__dirname)) {
@antelle
antelle / escape.js
Last active Mar 9, 2018
JS string escape
View escape.js
function escape(str) {
return str.replace(/[\n\r\\\'\u2028\u2029]/g, ch => {
if (ch === '\n') { return '\\n'; }
else if (ch === '\r') { return '\\r'; }
else if (ch === '\\') { return '\\\\'; }
else if (ch === '\'') { return '\\\''; }
else if (ch === '\u2028') { return '\\u2028'; }
else if (ch === '\u2029') { return '\\u2029'; }
else throw 'Bad char';
});
@antelle
antelle / combinatorics.js
Created Dec 16, 2017
Combinations & Permutations in JS
View combinatorics.js
let numbers = '1 2 3'.split(' ').map(n => +n);
getCombinations([], numbers, x => console.log('C', x.join(' ')));
getPermutations([], numbers, x => console.log('P', x.join(' ')));
function getCombinations(first, chars, cb) {
for (var i = 0; i < chars.length; i++) {
cb(first.concat(chars[i]));
getCombinations(first.concat(chars[i]), chars.slice(i + 1), cb);
}
View invisibles.txt
U+2060 foo⁠bar WORD JOINER
U+2061 foo⁡bar FUNCTION APPLICATION
U+2062 foo⁢bar INVISIBLE TIMES
U+2063 foo⁣bar INVISIBLE SEPARATOR
U+180E foo᠎bar MONGOLIAN VOWEL SEPARATOR
U+200B foo​bar ZERO WIDTH SPACE
U+200C foo€€‌bar ZERO WIDTH NON-JOINER
U+200D foo‍bar ZERO WIDTH JOINER
U+FEFF foobar ZERO WIDTH NO-BREAK SPACE
@antelle
antelle / FiddlerScript.cs
Last active Apr 3, 2020
Change response in Fiddler
View FiddlerScript.cs
static function OnBeforeRequest(oSession: Session) {
if (oSession.RequestMethod == 'GET' && oSession.PathAndQuery.IndexOf('part_of_your_url') > 0) {
oSession.utilCreateResponseAndBypassServer();
oSession.oResponse.headers.HTTPResponseCode = 401;
oSession.oResponse.headers.HTTPResponseStatus = '401 Not Authorized';
oSession.oResponse.headers['Access-Control-Allow-Origin'] = '*';
oSession.utilSetResponseBody('response_body');
}
}
@antelle
antelle / ImageMagick resize folder
Last active Aug 22, 2017
Batch resize with imagemagick
View ImageMagick resize folder
for f in *.JPG *.jpg; do convert "$f" -resize "1200x1200>" -quality 85 -verbose "$f"; done
@antelle
antelle / themes.scss
Created Sep 1, 2015
Modular SCSS theming
View themes.scss
// modified version of http://www.sitepoint.com/sass-theming-neverending-story/
// allows to write themified code without breaking modular project structure
// only one global variable
// Theme definitions
$themes: (
unicorn: (primary: hotpink, secondary: pink),
dragon: (primary: firebrick, secondary: red)
);
You can’t perform that action at this time.