Skip to content

Instantly share code, notes, and snippets.

@polonskiy
polonskiy / encrypted-git-repo.md
Created February 7, 2018 12:13
Transparent Git Encryption

Transparent Git Encryption

This document has been modified from its [original format][m1], which was written by Ning Shang (geek@cerias.net). It has been updated and reformatted into a [Markdown][m2] document by [Woody Gilk][m3] and [republished][m4].

Description

When working with a remote git repository which is hosted on a third-party storage server, data confidentiality sometimes becomes

@polonskiy
polonskiy / 10-custom.conf
Last active June 4, 2021 22:36
sysctl tuning for docker & serf
# values from https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Welcome%20to%20High%20Performance%20Computing%20%28HPC%29%20Central/page/Linux%20System%20Tuning%20Recommendations
# install (root): curl -s https://gist.githubusercontent.com/polonskiy/00a71bab32360ffcb79f/raw/10-custom.conf > /etc/sysctl.d/10-custom.conf
# apply (root): sysctl -p /etc/sysctl.d/10-custom.conf
net.ipv4.neigh.default.gc_thresh1 = 30000
net.ipv4.neigh.default.gc_thresh2 = 32000
net.ipv4.neigh.default.gc_thresh3 = 32768
net.ipv6.neigh.default.gc_thresh1 = 30000
net.ipv6.neigh.default.gc_thresh2 = 32000
@polonskiy
polonskiy / pre-commit
Last active March 20, 2020 07:39
PHPLint pre-commit git hook
#!/usr/bin/php
<?php
exec('git diff --name-only --diff-filter=ACM --cached', $files);
$status = 0;
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) != 'php') continue;
$file = escapeshellarg($file);
$message = array();
exec("git show :$file | php -l 2>&1", $message, $code);
@polonskiy
polonskiy / memcached2array.php
Last active January 28, 2019 11:16
dump memcached data
#!/usr/bin/php
<?php
$argv += [1 => 'localhost', 2 => 11211];
$memcached = new Memcached;
$memcached->addServer($argv[1], $argv[2]);
$result = [];
foreach($memcached->getAllKeys() as $k) $result[$k] = $memcached->get($k);
var_export($result);
echo ";\n";
@polonskiy
polonskiy / PHProutines.php
Created December 4, 2014 09:32
PHProutines
<?php
class Runner {
public function __construct() {
pcntl_signal(SIGCHLD, SIG_IGN);
}
public function go() {
if (pcntl_fork()) return;
@polonskiy
polonskiy / transmission-remote-magnet.bash
Created March 24, 2018 19:05 — forked from sbisbee/transmission-remote-magnet.bash
Quick and easy way of making Chrome send bittorrent magnet links to a remote Transmission instance using its API on Ubuntu with xdg.

Quick and easy way of making Chrome send bittorrent magnet links to a remote Transmission instance using its API on Ubuntu with xdg. This method does not require modifying any system files or xdg's scripts, whereas most of the examples I found on the Internet did require such hacks.

Chrome does not handle default applications, instead relying on the OS to manage that. The default handler in Ubuntu is xdg, which maps the MIME type to the default application. Extra tooling is required because xdg requires a registered desktop file, so you can't simply give it a command to run.

Steps:

  1. Install the shell script transmission-remote-magnet ideally in /usr/local/bin: ln -s ~/src/transmission-remote-magnet.bash transmission-remote-magnet

  2. Install the desktop file, which is required for xdg to work and will likely require sudo: desktop-file-install ./transmission-remote-magnet.desktop

@polonskiy
polonskiy / xkcd-pass.sh
Last active July 28, 2017 05:03
xkcd password generator
#!/bin/bash
LC_ALL=C grep '^[a-z]\+$' /usr/share/dict/words | shuf --random-source=/dev/urandom -n 4 | paste -s -d-
grep '^[abcdefghijklmnopqrstuvwxyz]\{3,7\}$' /usr/share/dict/words | shuf -n 6 | xargs | sed 's/ /-/g'
@polonskiy
polonskiy / segfault-finder.php
Created August 23, 2016 12:04 — forked from lyrixx/segfault-finder.php
How to find a segfault in PHP
<?php
register_tick_function(function() {
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
$last = reset($bt);
echo sprintf("%s +%d\n", $last['file'], $last['line']);
});
declare(ticks=1);
@polonskiy
polonskiy / rkxor.php
Last active August 8, 2016 11:12
Repeating-key XOR encryption
<?php
$data = file_get_contents('php://stdin');
$password = 'ps8T0G/39oHgRehuV0TjUv2lyeA=';
$c = rkxor($data, $password);
$x = rkxor($c, $password);
var_dump($c,$x);
function rkxor($data, $password) {
@polonskiy
polonskiy / gist:6914110
Created October 10, 2013 06:48
php lint
find . -name '*.php' -exec php -l {} \; | grep -v '^No'