Skip to content

Instantly share code, notes, and snippets.

View darkleaf's full-sized avatar

Mikhail Kuzmin darkleaf

View GitHub Profile
class User < ActiveRecord::Base
has_many :stories, :dependent => :destroy
has_many :tasks, :class_name => "Story",
:dependent => :nullify,
:foreign_key => "responsible_user_id"
attr_accessible :name, :email, :password, :password_confirmation
has_secure_password
validates_presence_of :password, :on => :create
@darkleaf
darkleaf / gist:3137207
Created July 18, 2012 16:11
ReversePolishNotation
module ReversePolishNotation
class << self
def calc(formula)
chain = prepare formula
stack = []
while chain.any? do
item = chain.shift
if item.kind_of? Float
stack.push item
else
require File.expand_path("../../config/environment", __FILE__)
OLD_BASE_DIR = "public/system/uploads/object_model"
FALLBACK_PATH = "/images/fallback/default.png"
def copy(model, mounter_name)
mounter = model.public_send(mounter_name)
if mounter.to_s != FALLBACK_PATH
basename = File.basename mounter.to_s
@darkleaf
darkleaf / gist:3360398
Created August 15, 2012 14:01
english, russian country-list
{ :name_ru => "Абхазия", :name_en => "Abkhazia", :alpha2 => "AB", :alpha3 => "ABH" }
{ :name_ru => "Австралия", :name_en => "Australia", :alpha2 => "AU", :alpha3 => "AUS" }
{ :name_ru => "Австрия", :name_en => "Austria", :alpha2 => "AT", :alpha3 => "AUT" }
{ :name_ru => "Азербайджан", :name_en => "Azerbaijan", :alpha2 => "AZ", :alpha3 => "AZE" }
{ :name_ru => "Албания", :name_en => "Albania", :alpha2 => "AL", :alpha3 => "ALB" }
{ :name_ru => "Алжир", :name_en => "Algeria", :alpha2 => "DZ", :alpha3 => "DZA" }
{ :name_ru => "Американское Самоа", :name_en => "American Samoa", :alpha2 => "AS", :alpha3 => "ASM" }
{ :name_ru => "Ангилья", :name_en => "Anguilla", :alpha2 => "AI", :alpha3 => "AIA" }
{ :name_ru => "Ангола", :name_en => "Angola", :alpha2 => "AO", :alpha3 => "AGO" }
{ :name_ru => "Андорра", :name_en => "Andorra", :alpha2 => "AD", :alpha3 => "AND" }
# gem install capybara --pre
# gem install rspec
# rspec capybara_test.rb
require 'rubygems'
require 'capybara'
require 'capybara/rspec'
Capybara.configure do |c|
c.current_driver = :selenium
@darkleaf
darkleaf / первая.py
Last active October 13, 2015 23:38
цои
import scipy.misc
import numpy as np
import matplotlib.pyplot as plt
import math
hx = 7.5
hy = 6.3
fi = -15 * np.pi / 180
kx = 1.2
ky = 0.9
Broadcast::ScheduleItem
=> Broadcast::ScheduleItem( ... time: time, ...)
i = Broadcast::ScheduleItem.last
i.time
=> 2000-01-01 10:50:07 UTC
i.time.class
=> Time
i.time.utc
=> 2000-01-01 10:50:07 UTC
Варианты инициализации views в backbone
=======================================
* в рельсовой вьюхе
* через jQuery селекторы (если есть id, инициализируем нужные вьюхи)
* через gon передавать контроллер и экшен
* написать роутер, основанный на window.location(придется отказаться от single page)
для всех, кроме последнего:
* инициализировать вьюхи
$ ->
$groups_selector = $('#user_advertisement_company_fb_page_id')
$fb_accounts_selector = $('#user_advertisement_company_facebook_account_id')
$stub_message = $('<option/>', text: 'Идет загрузка…')
group_filler = ->
if @value
previous_value = $('option', $groups_selector).val()
$groups_selector.html $stub_message
$.getJSON "/api/facebook_accounts/#{@value}/pages", (data) ->
@darkleaf
darkleaf / playbook
Created December 20, 2013 06:50 — forked from mokevnin/playbook
---
-
hosts: default
vars:
postgresql:
version: 9.1
password: my_secret_password
tasks: