Skip to content

Instantly share code, notes, and snippets.

View antelle's full-sized avatar

Dimitri Witkowski antelle

View GitHub Profile
@antelle
antelle / combinatorics.js
Created December 16, 2017 11:18
Combinations & Permutations in 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);
}
@antelle
antelle / invisibles.txt
Last active April 6, 2020 09:21
Invisibles
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 July 5, 2023 22:32
Change response in Fiddler
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 August 22, 2017 17:22
Batch resize with imagemagick
for f in *.JPG *.jpg; do convert "$f" -resize "1200x1200>" -quality 85 -verbose "$f"; done
@antelle
antelle / themes.scss
Created September 1, 2015 07:43
Modular SCSS theming
// 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)
);
@antelle
antelle / blink.css
Last active September 12, 2022 02:12
Blink
@antelle
antelle / String.format.js
Created October 17, 2013 09:31
Javascript simple string formatting function
// "{} {}".format("a", "b") => "a b"
// "{1} {0}".format("a", "b") => "b a"
// "{foo} {bar}".format({ foo: "a", bar: "b" }) => "a b"
String.prototype.format = function() {
var args = arguments;
var argNum = 0;
return this.replace(/\{(\w*)\}/gi, function(match) {
var curArgNum, prop = null;
if (match == "{}") {
curArgNum = argNum;
@antelle
antelle / HappyDebugging.java
Last active December 25, 2015 10:09
Put this to some deep place in your code before switching jobs (java version).
package net.antelle;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class Program implements java.util.Comparator<java.lang.String> {
public static void main(String [] args) {
happyDebugging();
System.out.format("compare result: %s", "abc".compareToIgnoreCase("trololo"));
}
@antelle
antelle / analyze_demo.py
Created May 25, 2013 21:17
SQLite ANALYZE demo
import sys
import os
import sqlite3
import json
import datetime
db = "tmp.sqlite"
def create_db():
if os.path.isfile(db):