Skip to content

Instantly share code, notes, and snippets.

View mamchenkov's full-sized avatar
🇨🇾
Working, one commit at a time.

Leonid Mamchenkov mamchenkov

🇨🇾
Working, one commit at a time.
View GitHub Profile
@mamchenkov
mamchenkov / product_clean.sh
Created October 24, 2014 08:49
Convert JPG product images to PNG, replacing white background with transparent one.
#!/bin/bash
# Cleanup product images
#
# This will convert images from JPG to PNG and replace the white
# background with transparent one.
#
# This is almost verbatim copy of the script from:
# http://tech.natemurray.com/2007/12/convert-white-to-transparent.html
<?php
// Sample data from data.csv
//line 1, product 1, feature 1
//line 2, product 1, feature 2
//line 3, product 1, feature 3
//line 4, product 2, feature 1
//line 5, product 3, feature 1
class Product {
// Product lines until we save
* -A in SSH enables agent forwarding.
* -p 2122 is not needed if you use the default port of 22.
* Replace SSH_USER and example.com with your own values.
* Example run: $ envoy run deploy_demo
* --no-scripts because Laravel composer.json's post-install-cmd includes optimize, which is already done by php artisan dump-autoload
@servers(['test' => '-A -p 2122 -l user test.example.com', 'prod' => '-A -p 2122 -l user example.com'])
@task('install_test', ['on' => ['test']])
cd project
@mamchenkov
mamchenkov / string-padding.php
Last active September 25, 2015 19:58
Partial string replacement with fixed width in PHP. Useful for things like credit card numbers.
<?php
/**
* Replace middle of the string with given char, keeping length
*
* <code>
* print padString('1234567890123456', 0, 0, 'x');
* </code>
*
* @param string $string String to process
* @param integer $start Characters to skip from start
@mamchenkov
mamchenkov / gist-test.txt
Created August 28, 2012 14:58
test of Gist vim plugin
This is a test of Gist vim plugin.
Hopefully, this will end up in my gists.
@mamchenkov
mamchenkov / vsprintf.php
Last active October 9, 2015 11:47
Nested sprintf() / vsprintf with gettext example
<?php
/**
* Example of sprintf()/vsprintf() with gettext
*/
/**
* String translation
*
* @param string $param String to translate
* @return string Translated string (surrounded by square brackets for visibility)
@mamchenkov
mamchenkov / xml-encode.php
Last active October 10, 2015 02:48
Encoding URLs for XML, using regular expressions
<?php
#
# Encoding URLs for XML, using regular expressions
#
# XML string
$string = '<page>some&page</page><page>some&otherpage</page><page>yet&anotherpage</page>';
$result =preg_replace_callback(
'#(<page>(.*?)</page>)#',
@mamchenkov
mamchenkov / ntpdate
Created September 12, 2012 19:05
ntpdate time synchronization
#!/bin/bash
/usr/sbin/ntpdate -s 0.fedora.pool.ntp.org
/usr/sbin/ntpdate -s 1.fedora.pool.ntp.org
/usr/sbin/ntpdate -s 2.fedora.pool.ntp.org
/sbin/hwclock -w
@mamchenkov
mamchenkov / js_lang.php
Created December 12, 2012 09:08
Return JavaScript with translated strings
<script type="text/javascript">
<?php
define('DEFAULT_LANGUAGE', 'en');
$lang = !empty($_REQUEST['lang']) ? $_REQUEST['lang'] : DEFAULT_LANGUAGE;
$translations = get_translations($lang);
if (!empty($translations)) {
foreach ($translations as $key => $value) {
@mamchenkov
mamchenkov / charts.php
Last active December 19, 2015 12:29
Quick and easy way to have multiple configurations for things like charts.
<?php
$charts = array(
'live1-ajax-total-count' => array(
'type' => 'line',
'title' => 'LIVE1 Total Count (ajax)',
'sql' => 'select .... ',
'callback' => 'minute_counts',
),
'live2-ajax-total-count' => array(
'type' => 'line',