Skip to content

Instantly share code, notes, and snippets.

@astashov
astashov / deglobalitor.rb
Created January 21, 2009 07:40
DeGlobalite (if you want to uninstall globalite plugin) the Rails app - change back all :something.l and :smthg.l_with_args(:a => "a") to 'Something' and 'Smthg a'
File.open("lang/ui/en-US.yml") do |file|
while line = file.gets
sym, translate = line.split(":", 2)
Dir['app/views/*/**', 'app/controllers/*', 'app/helpers/*'].each do |path|
lines = ""
File.open( path ) do |f|
lines = f.readlines
end
@astashov
astashov / heroku_submodules_remover
Created August 19, 2009 08:17
Creates/synchronizes new repo in the same parent dir with submodules tracked in the main tree and push the repo to Heroku
#!/bin/bash
current_dir=`pwd`
heroku_dir="${current_dir}_heroku"
function rsync_repo {
# Add trailing slash to source directory to avoid recreating it into $heroku_dir
rsync -r --exclude .git/ ${current_dir}/ $heroku_dir
}
# == css_js_generator
#
# It generates one big file from all CSS and from all JS small files. It
# scans public/stylesheets and public/javascripts, gets all files from there
# and creates application.css and application.js). Order can be specified
# in css_js_generator.rb. There are also 'notifier' script, it uses
# inotifywatch program for tracking changes in public directory and running
# css_js_generator.rb after every change in public directory. So, big files
# will be generated automatically and you don't need to run it
# css_js_generator.rb after every change of files in public dir.
FAQ for CSS Framework (http://gist.github.com/113972)
1. How are you using the "classes" var in JavaScript template?
Often, you need to make some manipulations with DOM objects. We almost don't use ids (#blabla) by our Law, only if this is really necessary for improving performance (if this is bottle-neck). But mostly, we use classes. I suggest to avoid using inline classes (because refactoring here is very often, and we often need to change name of classes), but use classes variable instead. E.g. use:
var classes = { some_class: 'b-something_some-class' };
$('.' + classes.some_class).hide();
FAQ for CSS Framework (http://gist.github.com/113972)
1. How are you using the "classes" var in JavaScript template?
Often, you need to make some manipulations with DOM objects. We almost don't use ids (#blabla) by our Law, only if this is really necessary for improving performance (if this is bottle-neck). But mostly, we use classes. I suggest to avoid using inline classes (because refactoring here is very often, and we often need to change name of classes), but use classes variable instead. E.g. use:
var classes = { some_class: 'b-something_some-class' };
$('.' + classes.some_class).hide();
@astashov
astashov / gist:1012345
Created June 7, 2011 14:20
will_paginate replacement
scope :paginate, lambda { |page, per_page| limit(per_page.to_i).offset((page.to_i - 1) * per_page.to_i) }
@astashov
astashov / css_js_principles.txt
Created September 3, 2011 08:44
General Organizational Principles for CSS and JS in Rails
==== General Organizational Principles for CSS and JS in Rails
=== Framework requirements
1. Modularity
2. Complex components are built from simple, atomic components
3. Cross-browser compatibility
a. Follow W3C standards
b. Keep IE hacks in a separate style file
4. Bulletproof
@astashov
astashov / yuras_task.rb
Last active December 17, 2015 21:29
Юрина задачка. Я не делал никаких проверок правильности ввода и схемы, будем считать что они все правильные. По сути, все что делает скриптик - конвертирует массив со схемой во что-то, что знает контекст получше, ну там когда какой тип данных встречается. А потом рекурсивно проходит по input'у и применяет схему.
require 'forwardable'
require 'pp'
# * Schema may be only an array
# * It may not contain an array, only a symbol or a hash
# * The key of a hash is always a symbol and the value is always an array or array inside an array
# * To show that it should iterate through a collection on input, we use array in array
class Schema
include Enumerable
extend Forwardable
@astashov
astashov / gist:b90c0888c25272399262
Last active October 13, 2016 16:37
Rebound.js-like spring animation in SCSS/SASS
$solver_timestamp_sec: 0.01;
// Rebound.js-like spring animations in SCSS.
// There is a bunch of functions, which helps generating keyframes for you spring
// animations, if you (like me) really want to avoid doing that in JavaScript.
//
// It only generates values for one spring, with given friction, tension and end value
// (i.e. it doesn't support spring systems)
// Friction and tension are matched to the values used in Origami, so you can use whatever
// your designers put in a Quartz Composer file in "Bouncy Animation" blocks :)
library maybe;
abstract class Maybe<T> {
T get value;
bool get isEmpty;
}
class Nothing extends Maybe {
get value => null;
bool get isEmpty => true;