Skip to content

Instantly share code, notes, and snippets.

<div style="font-family: monospace;font-size: 16px;text-align: center;width: 190px;color: white;background-color: #c00;transform: rotate(45deg);z-index: 9999; position: fixed; top: 30px; right: -50px;font-weight: bold;padding: 5px;cursor: pointer;opacity: 1;"
onclick="var s=this.style,p='opacity',t=setTimeout,i=function(){if(s[p]<1){s[p]-=-0.05;s.display='block';t(i,10);}else{s[p]=1;}},o=function(){if(s[p]>0){s[p]-=0.05;t(o,10);}else{s[p]=0;s.display='none';t(i,5e+3);}};o();">
<div style="border: 1px white dashed;">DEVELOPMENT</div>
</div>
@mleko
mleko / .gitconfig
Last active March 18, 2017 12:18
Git config
[core]
excludesfile = ~/.gitignore
pager = less -x4
[user]
name = Daniel Król
email = daniel@krol.me
[push]
default = simple
[merge]
ff = true
@mleko
mleko / gray_binary.c
Created April 7, 2017 11:19
Binary to Gray code (and reverse) conversion functions https://en.wikipedia.org/wiki/Gray_code
/**
The MIT License (MIT)
Copyright (c) 2017 Daniel Król
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH T
@mleko
mleko / lint.sh
Created April 19, 2017 16:18
PHP lint directory
#!/bin/sh
# ! inverts return code (fails on non-empty grep output)
! find . -type f -name '*.php' -exec php -l {} \; | grep -v "No syntax errors detected"
@mleko
mleko / .golang-gitlab-ci.yml
Last active April 29, 2017 17:17
Gitlab CI setup using docker image
image: golang:latest
stages:
- build
- test
before_script:
- go get github.com/tools/godep
- mkdir -p /go/src/gitlab.com
- cp -r /builds/$CI_PROJECT_NAMESPACE /go/src/gitlab.com/
- cd /go/src/gitlab.com/$CI_PROJECT_PATH
@mleko
mleko / remove-merged.sh
Created November 2, 2017 09:32
Git remove merged branches
#!/bin/sh
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
@mleko
mleko / git-tree.sh
Last active February 4, 2019 18:15
Print commit tree
#!/bin/sh
git log --graph --all --pretty=oneline --decorate --abbrev-commit --shortstat
# git config --global alias.tree "log --graph --all --pretty=oneline --decorate--abbrev-commit --shortstat"
function logColor(color, args) {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
const log = {
aliceblue: (...args) => { logColor('aliceblue', args)},
antiquewhite: (...args) => { logColor('antiquewhite', args)},
aqua: (...args) => { logColor('aqua', args)},
aquamarine: (...args) => { logColor('aquamarine', args)},
azure: (...args) => { logColor('azure', args)},
@mleko
mleko / simple-template.php
Last active July 16, 2018 13:35
Very simple template "engine"
<?php
function render($template, $vars) {
return \preg_replace_callback("!{{\s*(?P<key>[a-zA-Z0-9_-]+?)\s*}}!", function($match) use($vars){
return isset($vars[$match["key"]]) ? $vars[$match["key"]] : $match[0];
}, $template);
}
<?php
function array_permute($arrays) {
$set = array_shift($arrays);
foreach($arrays as $sub) {
$newSet = [];
foreach($set as $prefix) {
foreach($sub as $suffix){
$newSet[] = $prefix.$suffix;
}
}