Skip to content

Instantly share code, notes, and snippets.

View asabirov's full-sized avatar

Artur Sabrov asabirov

  • Apliteni.com
  • Spain
View GitHub Profile
check process nginx with pidfile /var/run/nginx.pid
start program = "/bin/systemctl start nginx"
stop program = "/bin/systemctl stop nginx"
@asabirov
asabirov / show-if-ready.directive.coffee
Created June 19, 2015 09:53
Show content if route is ready and xhr is done. (for algular's ui-router)
# <div app-show-if-ready ui-view></div>
appShowIfReady = ($animate, $rootScope, $timeout, cfpLoadingBar) ->
restrict: 'A'
link: ($scope, $element) ->
container = $element.parent()
stateChangeStartOff = $rootScope.$on '$stateChangeStart', ->
container.hide()
stateChangeSuccessOff = $rootScope.$on '$stateChangeSuccess', ->
$timeout ->
@asabirov
asabirov / nginx-fpm-host-generator.sh
Last active December 15, 2016 11:36
Generates Nginx configuration for vhost with PHP-FPM support
echo Please, enter domain name:
read DOMAIN_NAME
echo Please, enter domain IP:
read SERVER_IP
echo Please, enter domain directory:
read DOMAIN_DIR
echo "Please, enter Nginx config directory (default /etc/nginx/conf.d):"
read CONFIG_DIR
echo "Please, enter socket path (default /var/run/php7-fpm.sock):"
read SOCKET_PATH
@asabirov
asabirov / install-ioncube.sh
Last active April 2, 2018 07:24
Easy way to install ioncube on Debian/Ubuntu
wget http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
tar zxvf ioncube_loaders_lin_x86-64.tar.gz
PHP_CONFD="/etc/php5/conf.d"
PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
PHP_EXT_DIR=$(php-config --extension-dir)
cp "ioncube/ioncube_loader_lin_${PHP_VERSION}.so" $PHP_EXT_DIR
echo "zend_extension = ${PHP_EXT_DIR}/ioncube_loader_lin_${PHP_VERSION}.so" > "${PHP_CONFD}/00-ioncube.ini"
rm -rf ./ioncube
rm ioncube_loaders_lin_x86-64.tar.gz
service php5-fpm restart
@asabirov
asabirov / database.example.yml
Last active August 29, 2015 14:07
database.example.yml for postgres
development:
adapter: postgresql
host: localhost
port: 5432
pool: 5
encoding: unicode
database:
username:
password:
@asabirov
asabirov / spec_helper.rb
Last active August 29, 2015 14:07
Alternative for no-peeping-toms on Rails4
# add it to spec/spec_helper.rb
RSpec.configure do |config|
...
config.include TestObservers
...
end
@asabirov
asabirov / prepare-commit-msg
Last active August 29, 2015 14:01
Git hook which appends current branch name to commit message (.git/hooks/prepare-commit-msg)
#!/bin/sh
BRANCH=$(git rev-parse --abbrev-ref HEAD)
CURRENT=`grep -e "^[^#]" $1`
if [ -z "$CURRENT" ]
then
NEW_MSG=$(echo "$BRANCH"; cat "$1")
echo "$NEW_MSG" > $1
fi
@asabirov
asabirov / deploy.rb
Last active December 29, 2015 05:49
Task for capistrano which reload god configuration. php-resque+god+capistrano
namespace :god do
def god_command
"cd #{current_release}; ENV=#{env} SHARED=#{shared_path} bundle exec god"
end
def god_is_running
!capture("#{god_command} status >/dev/null 2>/dev/null || echo 'not running'").start_with?('not running')
end
desc "Stop god"
@asabirov
asabirov / php-resque.god
Last active December 29, 2015 05:49
Receipt for god to run and keep alive a php-resque process. It's also prevent memory leaks. php-resque + god
APP_PATH = File.dirname(__FILE__) + '/..'
SHARED = ENV['SHARED'] || APP_PATH
God.pid_file_directory = "#{SHARED}/tmp/pids"
God.watch do |w|
w.name = "resque"
w.log = "#{SHARED}/log/god.log"
w.pid_file = "#{SHARED}/tmp/pids/resque.pid"
w.interval = 30.seconds
w.stop_timeout = 30.seconds
@asabirov
asabirov / image_size.rb
Created November 15, 2012 10:42
Размер изображения
width, height = ARGF.read(24).unpack("@16N2")
p "width: #{width}px, height: #{height}px"
# $ ruby image_size.rb photo.jpg
# width: 400px, height: 500px