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 / git-commit-hash
Last active February 13, 2023 18:22
Find current git commit id/hash
$ git log -1 | grep ^commit | cut -d " " -f 2
dab96492ac7d906368ac9c7a17cb0dbd670923d9
$ git log -1 | grep ^commit | awk '{print $2}'
dab96492ac7d906368ac9c7a17cb0dbd670923d9
@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 / update_translations.sh
Created September 10, 2012 13:41
gettext translations update
#!/bin/bash
DOMAIN="easyforex"
POT="$DOMAIN.pot"
LANGS="en_US ru_RU"
SOURCES="*.php"
# Create template
echo "Creating POT"
rm -f $POT
@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',
@mamchenkov
mamchenkov / symlink.php
Last active December 19, 2015 16:18
Use the same script for different purposes, based on the name of the file being called (symlinks). Install: chmod +x symlink.php && ln -s another-symlink.php b.php Run: ./symlink.php --with A params && ./another-symlink.php --with B params