Skip to content

Instantly share code, notes, and snippets.

@mleko
mleko / color-run.sh
Last active January 15, 2022 19:50
Dry run and console color helper
#!/bin/bash
# Usage: `. color-run.sh`
# To perform dry run set `EXEC_DRY_RUN=1`
function colors {
# check if stdout is a terminal...
if test -t 1; then
# see if it supports colors...
git config --global alias.broom '!git branch --merged | egrep -v "(^\*|master|dev|release/next)" | xargs git branch -d'
<?php
class Stopwatch
{
/**
* @var array[]
*/
private $marks = [];
/**
@mleko
mleko / commit-template.php
Created July 16, 2018 13:31
Include feature branch name in commit message
#!/usr/bin/env php
<?php
$commitMsgFile = $argv[1];
$commitMsg = file_get_contents($commitMsgFile);
if(!\in_array(substr($commitMsg, 0, 1), ["\n", "\r"], true)) {
return;
}
<?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;
}
}
@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);
}
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 / 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"
@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 / .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