Skip to content

Instantly share code, notes, and snippets.

View keltanas's full-sized avatar
🇷🇺
justice will be served

Ke7Tana5 keltanas

🇷🇺
justice will be served
  • Saint Petersburg
View GitHub Profile
@keltanas
keltanas / account2pdf.php
Created June 13, 2012 22:45
Example export account to pdf
<?php
set_include_path($_SERVER['DOCUMENT_ROOT']);
require_once 'engine.php';
// подключаем библиотеку
require_once('tcpdf/config/lang/rus.php');
require_once('tcpdf/tcpdf.php');
//require_once('../class/imo_account_pdf.php');
@keltanas
keltanas / example001.js
Created August 13, 2012 15:57
Пример смены контекста
for ( n=1; n<=3; n++ ){
$.get( url, $.proxy( function( n, data ){
console.log(arguments, n, data);
}, n));
}
@keltanas
keltanas / gist:3499449
Created August 28, 2012 15:59
Плагин для twitter bootstrap, открывает dropdown меню при наведении, если оно находится внутри navbar
/**
* Плагин для twitter bootstrap, открывает dropdown меню при наведении, если оно находится внутри navbar
* <div class="navbar" id="menu1">...</div>
* <script type="javascript">$(document).ready(function(){
* $('#menu1').dropdownMouse()
* });</script>
* @return {*}
*/
$.fn.dropdownMouse = function()
{
@keltanas
keltanas / gravatar.php
Created September 9, 2012 23:46
Gravatar request example
<?php
/**
* Gravatar request example
* @author Nikolay Ermin <nikolay@ermin.ru>
* @link http://siteforever.ru
*/
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
<?php
//...
function settingCONF_BYCOUNTRY_BYZONE_FORM($module_id)
{
$curr_country = isset($_POST["shipping_module_bycountry_byzone_country"]) ? $_POST["shipping_module_bycountry_byzone_country"] : 0;
$curr_country = (int) $curr_country;
if(!$curr_country){
$curr_country = xGetData('SXshipping_module_bycountry_byzone_country'.$module_id);
@keltanas
keltanas / gist:4182125
Last active October 13, 2015 10:28
В чем разница?
<?php
// <= PHP 5.2
$cities = array_filter($cities,create_function('$v','return count($v);'));
// >= PHP 5.3
$cities = array_filter($cities,function($v){return count($v);});
// VS
@keltanas
keltanas / testClosure.php
Created December 13, 2012 17:36 — forked from anonymous/testClosure.php
Вернем анонимную функцию, которая берет $this от родительского метода и возвращает его. Работает в PHP 5.4+ Демонстрирует видимость переменной $this в замыкании (в PHP 5.3 замыкать объект приходится через техническую переменную)
<?php
class test
{
public function do_test()
{
return function() {
return $this;
};
}
}
@keltanas
keltanas / true_closure.py
Created December 24, 2012 18:20
Передаем ссылку на объект через лямда-функцию
__author__ = 'keltanas'
class closure:
def get_me(self):
return lambda : self
inst_test = closure()
me = inst_test.get_me()
del inst_test
@keltanas
keltanas / gist:4374759
Created December 25, 2012 18:47
Тестирование демо-блога на tornado в локалхосте. Процессор Corei5 mobile.
keltanas@kelbook:~/PycharmProjects/tornado/static$ ab -n 10000 -c 1000 http://localhost:8888/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
// Шаг 1
function(){} // объявляем анонимную функцию
// Шаг 2
(function(){})(); // - объявляем и запускаем анонимную функцию
// Шаг 3
(function($){