Skip to content

Instantly share code, notes, and snippets.

View AgentCoop's full-sized avatar

Agent Cooper AgentCoop

  • Belarus, Minsk
View GitHub Profile
@AgentCoop
AgentCoop / *.js
Created July 10, 2018 06:48
EcmaScript 6 fibonacci numbers
function* fibonacci(n, current = 0, next = 1) {
if (n<1)
return 0;
yield current;
yield* fibonacci(n - 1, next, current + next)
}
const fib20 = fibonacci(20);
@AgentCoop
AgentCoop / Systemd Docker containers startup
Last active February 17, 2017 10:17
Example of how to start docker containers on system startup
[Unit]
Description=Docker container cdn-redis
Requires=docker.service
After=docker.service
[Service]
Restart=always
RestartSec=3
ExecStartPre=-/usr/bin/docker rm -f cdn-redis
ExecStart=/usr/bin/docker run --name=cdn-redis -v /data/cdn.ewf/redis:/data/cdn.ewf/redis cdn-redis:latest
String.prototype.repeat= function(n){
n = n || 1;
return Array(n+1).join(this);
}
function sleep(delay) {
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
@AgentCoop
AgentCoop / gist:a5d9560820432defe640
Last active February 18, 2016 09:13
Text editing in Firefox
// Convert all words in uppercase to capitalized ones
var a = $('textarea').text().replace(/((?!ВКС|РФ|СМИ)([А-Я])([А-Я\-]+))/g,
function(match, p1, p2, p3) { return p2 + p3.toLowerCase() });
$('textarea').text(a)
@AgentCoop
AgentCoop / gist:8455450
Created January 16, 2014 14:00
Backofifce for the poor, i.e. start-ups
1 #! /usr/bin/bash
2
3 query_exec ()
4 {
5 # ssh -T for remote SSH connection
6 echo "$1" | mysql -uroot -proot -N test
7 }
8
9 employees=$(query_exec 'SELECT id,id,firstname,lastname,age FROM `employee` test')
10
# Remove the leading capital C letter from PHP filenames
for filename in $(find -type f -name "C*.php");
do
new=$(echo $filename | sed -r 's/C([A-Z].*\.php)/\1/');
echo $new;
git mv $filename $new;
done
@AgentCoop
AgentCoop / gist:6006268
Created July 16, 2013 06:30
Some statistics about PHP and the Linux kernel code base
PHP:
r00t:php# git log --format=%H --numstat --no-merges | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d, diff=%d, rate=%0.4f\n", plus, minus, plus-minus,minus/plus)}'
+10281181, -7373425, diff=2907756, rate=0.7172
Linux kernel:
r00t:linux# git log --format=%H --numstat --no-merges | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d, diff=%d, rate=%0.4f\n", plus, minus, plus-minus,minus/plus)}'
+38145990, -20701172, diff=17444818, rate=0.542