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 / selected.rb
Created June 7, 2013 01:44
Select with selected option
- options = options_for_select(Landing::TYPES.collect{ |name| [ t(".#{name}"), name ] }, @landing.landing_type)
= f.select :landing_type, options
@the-teacher
the-teacher / JQ.UI.autocomplite.coffee
Created June 7, 2013 04:50
autocomplite source example
class @App
@kb_suggest = (request, response) ->
response [{
label: 'label'
value: 'key'
}]
$('#landing_iata_one').autocomplete
source: App.kb_suggest
@the-teacher
the-teacher / app.js.coffee
Created June 9, 2013 09:27
Rails flash messages + Twitter bootstrap + HAML + Coffee
$ ->
$('.flash_msgs').on 'click', 'a.close', ->
$(@).parent().hide()
@the-teacher
the-teacher / bat_file.bat
Created July 2, 2013 08:09
bat file example
ECHO OFF
cls
ECHO.
ECHO FILE NAME
ECHO %0
ECHO.
@the-teacher
the-teacher / install.txt
Last active December 20, 2015 01:49
Debian install
Prepare
apt-get update && apt-get upgrade
apt-get -f install
apt-get install dialog
Base
apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxslt1.1 libxslt1-dev libxml2 libxml2-dev libxslt-dev autoconf libc6-dev -y
ImageMagick
apt-get install aptitude -y
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn_<%= application %>
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
@the-teacher
the-teacher / test.rb
Created August 10, 2013 13:14
Interpolation vs concatenation
1.8.7 :009 > Benchmark.bm{ |b| b.report{ 100_000.times{ Rails.root + 'a/b/c' } } }
user system total real
4.890000 0.010000 4.900000 ( 5.407428)
=> true
1.8.7 :010 > Benchmark.bm{ |b| b.report{ 100_000.times{ Rails.root.to_s + 'a/b/c' } } }
user system total real
0.220000 0.000000 0.220000 ( 0.272255)
=> true
1.8.7 :011 > Benchmark.bm{ |b| b.report{ 100_000.times{ "#{Rails.root}/a/b/c" } } }
user system total real
@log = -> console.log.apply(console, arguments)
class @Animal
constructor: (name = 'Abstract animal') ->
@name = name
Animal::eat = (food) ->
log(food)
class @Dog extends Animal
lng_corr = 250 / (Math.cos(coordinates[1] * Math.PI / 180) * 111.11) / 2
lat_corr = 250 / 111.11 / 2
query = City.find().where('coordinates.lng').gt(coordinates[0] - lng_corr).lt(coordinates[0] + lng_corr).where('coordinates.lat').gt(coordinates[1] - lat_corr).lt(coordinates[1] + lat_corr)
@the-teacher
the-teacher / conv.rb
Last active December 21, 2015 13:09
Trim PNG files
require 'fileutils'
ROOT_PATH = File.dirname File.absolute_path(__FILE__)
src_dir = ROOT_PATH + "/src"
dest_dir = ROOT_PATH + "/dest"
src_dirs = Dir.glob(src_dir + '/*').select{|f| File.directory? f }
src_dirs.each do |dir|
dir_name = dir.split('/').last