Skip to content

Instantly share code, notes, and snippets.

@mitio
mitio / routes.rb
Created July 26, 2012 08:10
Rails Routes Constraints By Subdomain
constraints(lambda { |req| req.host.to_s =~ /\Aadmin./ }) do
namespace :admin, :path => '/' do
root :to => 'dashboards#show' # => that's Admin::DashboardsController#show in app/controllers/admin/dashboards_controller.rb
resources :users # => Admin::UsersController in app/controllers/admin/users_controller.rb
resources :posts # => Admin::PostsController in app/controllers/admin/posts_controller.rb
end
end
@mitio
mitio / Gemfile
Created June 12, 2012 20:21
Rails 3.2 + RSpec 2.8 + Spork + Guard + Growl
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails', :require => false
gem 'shoulda-matchers'
end
group :development do
gem 'guard-rspec'
gem 'guard-spork'
# For Growl notifications
@mitio
mitio / gist:2377761
Created April 13, 2012 15:36
Windows Instructions
Здрасти :)
Малко бележки относно това какво съм сложил и как да си поддържате компютъра във форма.
1. Сложил съм легален Windows XP със Service Pack 2 (не е пиратски, съвсем легитимен си е)
2. Сложил съм антивирусна програма - Microsoft Security Essentials. От Microsoft e и е безплатна за хората, които
имат легален Windows. Не слагайте друга антивирусна или защитна програма, тази ви стига.
3. Сложил съм два браузъра - Google Chrome и Mozilla Firefox. Можете да ползвате който искате от двата, за да
@mitio
mitio / rails_asset_pipeline_compiled_files.rb
Created March 7, 2012 11:14
Where the Rails' asset pipeline searches for asset files and how the config.assets.precompile directive works
# Test the result of config.assets.precompile
#
# Check which files will be regarded as "manifests" and thus precompiled and be
# available for standalone use via the /assets/<asset> URL when in production.
# Execute this code in your Rails console.
# First, you'll probably be in development mode, so add here your
# additional production precompile patterns you want to test against.
precompile = Rails.configuration.assets.precompile + [/^.+\.css$/, 'active_admin.js']
@mitio
mitio / generate_test.py
Created February 10, 2012 23:24
Testgen-based test generator
# -*- coding: utf-8 -*-
import sys
import os
import os.path
from os.path import join, realpath
import random
from buildFromTex import main as build
from lib.textreader import TextTestReader as Reader
@mitio
mitio / hardcore.md
Created January 23, 2012 17:20
Hardcore

Хард-кор програмист?

Моето скромно мнение е следното — "хард-кор" е състояние на чувствата, а не на знанията (макар че второто е в правопропорционална зависимост с първото). Бегъл опит за дефиниця:

  • Ако не можете да си представите живота като непрограмист, вероятно сте хард-кор.
  • Ако търсите нов език за програмиране/framework, защото тези, които ползвате в момента не ви пасват, вероятно сте хардкор.
  • Ако сте открили бъг и не можете да спите, докато не разберете причината за него, вероятно сте хард-кор.
  • Ако чувствате, че знанията ви в областта са нищожно количество и изгаряте от желание да трупате все повече и повече такива, вероятно сте хард-кор.
  • Ако усещате, че количеството интересни и нови неща в сферата ви се увеличава по-бързо, отколкото можете да ги консумирате, вероятно сте хард-кор.
  • Ако не ви пука особено, че от прекалено дългото взиране в една точка на около 30 см пред очите ви вече носите очила, вероятно сте хард-кор.
@mitio
mitio / crud_event_logger.php
Created January 5, 2012 12:19
Simple CrudEventLogger
<?
// in lib/classes/crudeventlogger.php
class CrudEventLogger {
protected $event = null;
protected $table_name = null;
protected $record_id = null;
protected $user_id = null;
protected $before = array();
protected $after = array();
@mitio
mitio / gist:1561699
Created January 4, 2012 19:48
ArgumentError: wrong number of arguments (3 for 2) for sass-rails 3.2.3 and Rails 3.2.rc1
actionpack (3.2.0.rc1) lib/sprockets/helpers/rails_helper.rb:118:in `compute_source_path'
sass-rails (3.2.3) lib/sass/rails/template_handlers.rb:23:in `source_path'
sass-rails (3.2.3) lib/sass/rails/template_handlers.rb:84:in `sass_options'
sass-rails (3.2.3) lib/sass/rails/template_handlers.rb:106:in `evaluate'
tilt (1.3.3) lib/tilt/template.rb:76:in `render'
sprockets (2.1.2) lib/sprockets/context.rb:177:in `block in evaluate'
sprockets (2.1.2) lib/sprockets/context.rb:174:in `each'
sprockets (2.1.2) lib/sprockets/context.rb:174:in `evaluate'
sprockets (2.1.2) lib/sprockets/processed_asset.rb:12:in `initialize'
sprockets (2.1.2) lib/sprockets/base.rb:241:in `new'
@mitio
mitio / gist:1343383
Created November 6, 2011 19:54
Don't Use MongoDB

Don't use MongoDB

I've kept quiet for awhile for various political reasons, but I now feel a kind of social responsibility to deter people from banking their business on MongoDB.

Our team did serious load on MongoDB on a large (10s of millions of users, high profile company) userbase, expecting, from early good experiences, that the long-term scalability benefits touted by 10gen

@mitio
mitio / checksum.html
Created October 5, 2011 11:00
Binary calculations in JavaScript (checksum byte computation)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script>
function E(id) {
return document.getElementById(id);
}
window.onload = function () {