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
# Gratheon Individual Contributor License Agreement
Thank you for your interest in contributing to Gratheon ("We" or "Us").
This Contributor License Agreement ("Agreement") documents the rights granted
by contributors to Us. To make this document effective, please sign it and
send it to Us by email at [email protected], or submit it through our
CLA Assistant bot on GitHub.
This is a legally binding document, so please read it carefully before agreeing
@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://[email protected] <<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 . ' ';
@tot-ra
tot-ra / gist:5192168
Created March 18, 2013 23:53
Conversion of number to one of the countable forms in russian
function num2MultipleRus($int){
$str=strval($int);
$fin=$str[strlen($str)-1];
if ($fin==1) return 1;
elseif ($fin>1 && $fin<5) return 2;
elseif ($fin>4) return 3;
}