Skip to content

Instantly share code, notes, and snippets.

View the-teacher's full-sized avatar
💻
Working remotely

Ilya N. Zykin the-teacher

💻
Working remotely
View GitHub Profile
@the-teacher
the-teacher / class_exists.rb
Created August 23, 2013 13:08
ruby check for class exists
# the_class_exists? :User => true | false
# the_class_exists? :Role => true | false
def the_class_exists?(class_name)
klass = Module.const_get(class_name)
return klass.is_a?(Class)
rescue NameError
return false
end
CSV_FIELDS = %w[
title
landing_type
point_nom_from
iata_from
point_nom_to
iata_to
<lastmod>strftime("%FT%R%:z")</lastmod>
#!/bin/csh
mkdir -p /home/nginx/data/www/db_dumps
cd /home/nginx/data/www/db_dumps
set filename="open_cook_"`date +%Y-%m-%d_%H-%M`".sql"
mysqldump -u root -pPASSWORD open_cook_pro --complete-insert > $filename
#!/bin/csh
set dump_dir=/home/nginx/data/www/dir_dumps
set ls=/bin/ls
set tar=/usr/bin/tar
set dump_file="open_cook_"`date +%Y-%m-%d`".tar"
set dump_path=/home/nginx/data/www/capistrano/open-cook.ru/shared/uploads
mkdir -p $dump_dir
cd $dump_dir
@the-teacher
the-teacher / is_mobile.rb
Created September 6, 2013 16:36
mobile device test
def is_mobile? _agent
check_1 = /(android|ipad|playbook|silk|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.match(_agent)
check_2 = /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro
require 'rubygems'
require 'hominid'
require 'json'
API_KEY = '000000000000000000000000000-us4'
TEST_EMAIL = '[email protected]'
def get_count
h = Hominid::API.new(API_KEY)
list_id = h.lists['data'].last['id']
TheComments::Engine.routes.draw do
resources :comments do
member do
post :to_spam
post :to_draft
post :to_published
delete :to_deleted
end
collection do
@the-teacher
the-teacher / gist:7331900
Created November 6, 2013 06:39
kaminari.spec.env
$ bundle install --gemfile ./gemfiles/active_record_40.gemfile
$ export BUNDLE_GEMFILE=$PWD/gemfiles/active_record_40.gemfile
$ echo $BUNDLE_GEMFILE
$ bundle exec rake spec
$ export -n BUNDLE_GEMFILE