Skip to content

Instantly share code, notes, and snippets.

View tot-ra's full-sized avatar
🐝
Processing video with AI

Artjom Kurapov tot-ra

🐝
Processing video with AI
View GitHub Profile
import psutil
import threading
if is_local_env():
def print_memory_usage():
process = psutil.Process()
while True:
logger.debug("Memory usage: %d mb", process.memory_info().rss / (1024 * 1024))
time.sleep(1)
for b in `git branch | grep -v \*`; do git branch -D $b; done
@tot-ra
tot-ra / autoloader.php
Created November 23, 2019 12:37
Autoloader pseudocode
final class Loader{
// spl_autoload_register([$this, 'loadClass'], true, $prepend);
public function findFile($class){
//...
/* autoload core without namespace classes */
if (is_file($location = ROOTPATH . 'application/core/' . $class . EXT)) {
return $location;
}
/* autoload library classes */
if (is_file($location = ROOTPATH . 'application/libraries/' . $class . EXT)) {
@tot-ra
tot-ra / mass_db_insert
Created December 15, 2015 11:29
table_load_test.sql
/* repeat X times to get (table cardinality)^X number of rows in it */
INSERT IGNORE INTO table_to_flood (a,b) SELECT FLOOR(RAND()*100000), UUID() FROM table_to_flood;
@tot-ra
tot-ra / gist:8f92208162310d643305
Created May 27, 2014 10:04
angularjs sprintf filter
app.filter['sprintf'] = function () {
return function (str, number) {
function parse(str) {
var args = [].slice.call(arguments, 1),
i = 0;
str = str.replace(/{(\d+)}/g, function (a, number) {
return typeof args[number] != 'undefined'
? args[number]
@tot-ra
tot-ra / gist:7675047
Created November 27, 2013 12:43
bash script to download file(s) over ftp to local dir
#!/bin/bash
lftp -u login,pass ftp://login@example.com <<EOF
mget -d -O /local/path/to/save/to /remote/path/to/dir/*.BIN
EOF
@tot-ra
tot-ra / update.sh
Created November 20, 2013 08:22
GIT staging update shell script
cd /var/www/html
git clean -f
git fetch --all
#git pull origin master
git reset --hard origin/master
@tot-ra
tot-ra / BitField.php
Created May 29, 2013 06:24
bit field
<?php
/**
* Manages variable as bitfield
*/
class BitField {
private $value;
/**
* @param int $value initial value
@tot-ra
tot-ra / gist:5269960
Created March 29, 2013 09:56
Short PHP code highlighting function
function php_highlight($source, $classes = true) {
$r1 = $r2 = '##';
// adds required PHP tags (at least with vers. 5.0.5 this is required)
if (strpos($source, ' ?>') === false) // xml is not THAT important ;-)
{
$source = "<?php " . $source . " ?>";
$r1 = '#&lt;\?.*?(php)?.*?&nbsp;#s';
$r2 = '#\?&gt;#s';
}
@tot-ra
tot-ra / gist:5192182
Created March 18, 2013 23:54
Text DIFF with highlighting
function htmlDiff($old, $new, $exceptions = array()) {
$ret = '';
$diff = diff(explode(' ', $old), explode(' ', $new), $exceptions);
foreach ($diff as $k) {
if (is_array($k)) {
$ret .= (!empty($k['d']) ? "<del style='background:#FFFF00;'>" . implode(' ', $k['d']) . "</del> " : '') . (!empty($k['i']) ? "<ins style='background:#00FF00;'>" . implode(' ', $k['i']) . "</ins> " : '');
}
else {
$ret .= $k . ' ';