Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / init.sh
Created February 12, 2015 14:33
forward signals
#!/bin/bash
#enable job control
set -m
#propagate INT/TERM signals
trap 'kill -TERM $(jobs -p); wait' TERM
trap 'kill -INT $(jobs -p); wait' INT
#services
@polonskiy
polonskiy / float-comma.php
Last active August 29, 2015 14:16
comma deciaml separator
<?php
setlocale(LC_ALL, 'uk_UA.UTF-8');
$float = 1.2345;
echo "$float\n";
@polonskiy
polonskiy / csv-decode.php
Last active August 29, 2015 14:23
csv decode
<?php
function csv_decode($csv, $columns = [], $delimiter = ',', $enclosure = '"', $escape = '\\') {
$tmp = fopen('php://temp', 'rb+');
fwrite($tmp, $csv);
rewind($tmp);
$result = [];
$assoc = (bool) $columns;
@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 / 1.sh
Last active February 24, 2016 07:49
remove old kernels
#!/bin/bash
dpkg -l | awk '/linux-image-[0-9]/ {print $2}' | grep -vF "$(uname -r)" | xargs -r apt-get -y purge
@polonskiy
polonskiy / git-del.sh
Created September 22, 2015 11:22
remove file from git
#!/bin/bash
git filter-branch --prune-empty --index-filter "git rm --cached -f --ignore-unmatch $1" --tag-name-filter cat -- --all
@polonskiy
polonskiy / array_of_example.php
Last active January 21, 2016 09:24 — forked from bernik/array_of_example.php
array_of realization in php
<?php
class User {
public
$name,
$lastName;
public function __construct($name, $lastName) {
$this->name = $name;
$this->lastName = $lastName;
@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);