Skip to content

Instantly share code, notes, and snippets.

View smuuf's full-sized avatar

Přemysl Karbula smuuf

View GitHub Profile
@smuuf
smuuf / gist:f3d511d6f81b39f07dab
Created January 21, 2015 13:50
PHP 5.6 keywords and stuff (as of 21.01.2015)
PHP 5.6 keywords and stuff (as of 21.01.2015)
---
PHP Keywords:
(http://php.net/manual/en/reserved.keywords.php)
__halt_compiler()
abstract
and
array()
@smuuf
smuuf / CrudeForm.php
Created February 14, 2016 11:52
Crude Form class example
<?php
/**
* A very basic crude Form class.
* It can have input controls + will know their values.
* Also will know if it (the form) was itself submitted.
*/
class CrudeForm {
/** @var string Form name for identifying the form. **/
// Sine
__().sine({id:"kurva"}).lowpass(220).reverb({
seconds: 3,
decay: 2,
}).dac(0.5);
// Loop
__.loop({steps:8,interval: 400});
var k =__("#kurva");
// Prepare some stuff.
var bpm = 135;
var loopInterval = (60 * 1000) / bpm / 4;
// Master channel.
__().compressor({id: "master"}).dac();
__().sine({id: "kick", frequency: 60})
.overdrive({drive: 0.05})
.adsr({id: "kickA"})
@smuuf
smuuf / alembic_filename_date.php
Last active January 11, 2017 11:42
Rename Alembic migrations to contain date time (PHP)
<?php
// This script ONLY RETURNS BASH COMMANDS that would take care of the renaming.
// Usage:
// alembic_filename_date.php --glob=<glob_pattern:*.py> --format=<date_format:Y-m-d_H-i_>
$optGlob = '*.py';
$optFormat = 'Y-m-d_H-i_';
#!/bin/bash
if [[ -f $1 ]]; then
cat $1 | while read line
do
youtube-dl --no-mtime --no-post-overwrites --extract-audio --audio-format mp3 --audio-quality 192K $line
done
else
@smuuf
smuuf / docker-run
Last active September 22, 2017 05:25
Access Docker host IP as "localhost" inside container when using Docker on Windows Hyper-V backend
# Docker client inside WSL + Container running under Docker on Windows (tested on Hyper-V's VM)
docker run --add-host=localhost:$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1) -it <...containerID...> /bin/bash
function lines_as_progress {
echo -ne "█ ("$@") "
stdbuf --output=L --error=L "$@" 2>&1 |
while IFS= read -r line
do
printf "."
done
printf " Done"
echo
}
@smuuf
smuuf / fblimit.php
Created November 10, 2017 17:11
Facebook Crawler Request Rate Limiter
<?php
// Number of requests permitted for facebook crawler per second.
const FACEBOOK_REQUEST_THROTTLE = 20;
const FACEBOOK_REQUESTS_JAR = __DIR__ . '/.fb_requests';
const FACEBOOK_REQUESTS_LOCK = __DIR__ . '/.fb_requests.lock';
$ua = $_SERVER['HTTP_USER_AGENT'] ?? false;
if ($ua && strpos($ua, 'facebookexternalhit') !== false) {
@smuuf
smuuf / git_status_in_function.sh
Last active November 30, 2018 10:47
git status in prompt function
#!/bin/bash
get_git_status() {
git_status=$(git status -s -u -v 2>/dev/null)
if [[ -z "$git_status" ]]; then return 0; fi
modified=$(echo "$git_status" | grep '^ M ' | wc -l)
deleted=$(echo "$git_status" | grep '^ D ' | wc -l)
untracked=$(echo "$git_status" | grep '^?? ' | wc -l)
echo "(~$modified -$deleted +$untracked) "
}