Skip to content

Instantly share code, notes, and snippets.

View glagola's full-sized avatar

Igor Glagola glagola

View GitHub Profile
@glagola
glagola / .gitignore
Created June 3, 2013 07:43
.gitignore template for empty folders, which must be in repo
*
!.gitignore
// The .config() part is the relevant part, 'SomeModule' is arbitrary name,
// but this config() call goes on your main ng-app="YourAppModule"
// The PHP $_POST expects data w/ a form content type, not a JSON payload
angular.module("YourAppModule", ["SomeModule"]).config(function($httpProvider) {
$httpProvider.defaults.headers.put['Content-Type'] =
'application/x-www-form-urlencoded';
$httpProvider.defaults.headers.post['Content-Type'] =
'application/x-www-form-urlencoded';
});
# Enforce mysql to set utf8 on every connection
# place this file in /etc/mysql/conf.d
[mysqld]
skip-character-set-client-handshake
collation-server=utf8_unicode_ci
character-set-server=utf8
@glagola
glagola / gist:4109816
Created November 19, 2012 09:26
Транслитирирует русский текст в английский
<?php
function rus2translit($text)
{
// Русский алфавит
$rus_alphabet = array(
'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й',
'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф',
'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я',
'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й',
@glagola
glagola / gist:3942156
Created October 23, 2012 22:32
Распознавание кодировки строки
<?php
function detect_encoding($string, $pattern_size = 50)
{
$list = array('cp1251', 'utf-8', 'ascii', '855', 'KOI8R', 'ISO-IR-111', 'CP866', 'KOI8U');
$c = strlen($string);
if ($c > $pattern_size)
{
$string = substr($string, floor(($c - $pattern_size) /2), $pattern_size);
$c = $pattern_size;
@glagola
glagola / gist:3931984
Created October 22, 2012 15:17
file_get_contents proxy
<?php
$url = 'http://www';
$proxy = 'tcp://xxx:8080';
$context = array(
'http' => array(
'proxy' => $proxy,
'request_fulluri' => True,
@glagola
glagola / smartCut
Created September 25, 2012 07:51
Обрезает строку по длине, не разрезая слова. Корректно работает с UTF-8.
<?php
function smartCut($str, $len, $enc = 'UTF-8') {
return (mb_strlen($str, $enc) > $len) ? mb_substr($str, 0, mb_strpos($str, ' ', $len, $enc), $enc) : $str;
}
@glagola
glagola / gist:3447864
Created August 24, 2012 09:07
List Files deeply
<?php
function files($dir, $callback) {
$queue = array($dir);
$r = -1;
$w = 0;
while ($r < $w) {
$path = $queue[++$r];
@glagola
glagola / gist:2843814
Created May 31, 2012 14:36
Get first day of previous month
<?php
$t = strtotime('first day of previous month');
@glagola
glagola / google-chrome-optimizer
Created May 31, 2012 11:01
google-chrome-optimizer
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.