Skip to content

Instantly share code, notes, and snippets.

View markevich's full-sized avatar

Slava Markevich markevich

  • Georgia, Tbilisi
  • 13:03 (UTC +04:00)
View GitHub Profile
@markevich
markevich / gist:6578142
Created September 16, 2013 08:49
Remove all local merged branches
git branch --merged | grep -v \* | xargs git branch -D
@markevich
markevich / gist:6697592
Created September 25, 2013 10:04
Except for relation
has_many :items, inverse_of: :order, class_name: 'OrderItem', dependent: :destroy do
def except(id)
where(OrderItem.arel_table[:id].not_eq(id))
end
end
@markevich
markevich / gist:7037839
Last active December 25, 2015 20:49
vim convert ruby 1.8 has syntax to 1.9
%s/:\([^ ]*\)\(\s*\)=>/\1:/g
# This custom matcher can be used to test state machine
#
# Examples
#
# transition = OpenStruct.new(:name => :operation1, :state_field => :status, :from => :state1, :to => :state2)
# it { should have_transition(transition) }
#
# transition = {:name => :operation2, :state_field => :status, :from => :state2, :to => :state3}
# it { should have_transition(transition) }
RSpec::Matchers.define :have_transition do |transition|
@markevich
markevich / gist:7228804
Created October 30, 2013 08:10
Show activerecord validation errors in log
# model
after_validation :log_errors, :if => Proc.new {|m| m.errors}
def log_errors
Rails.logger.debug self.errors.full_messages.join("\n")
end
$ rails g model switchable_plan origin:references replacement:references 'switch_plan_fee:decimal{15,2}'
# app/models/switchable_plan.rb
class SwitchablePlan < ActiveRecord::Base
belongs_to :origin
belongs_to :replacement
end
# db/migrate/20131128082637_create_switchable_plans.rb
class CreateSwitchablePlans < ActiveRecord::Migration
require 'yaml'
desc "Generates database.yml, optional arguments are allowed: [username, password, adapter, project_path]"
task :dbconfig => 'database.yml'
file 'database.yml', [:username, :password, :adapter, :project_path] do |t, args|
Dir.chdir('config')
args.with_defaults(:project_path => Dir.pwd)
DBConfigGenerator.new(t, args).generate
end

3D CSS Sphere

3D ball made with just some CSS 3D transforms, border-radius and border-style. Not really useful, it just looks nice...

A Pen on CodePen.

License.

@markevich
markevich / elixir_sips.exs
Last active August 29, 2015 14:25 — forked from sheharyarn/elixir_sips.exs
Download videos from ElixirSips.com
defmodule Episode do
defstruct id: nil, name: nil, video: nil, markdown: nil, post: nil
def get_all do
[
%Episode{id: "001", post: "271", name: "Introduction and Installing Elixir", video: "1366", markdown: "1382"},
%Episode{id: "002", post: "275", name: "Basic Elixir", video: "1367", markdown: "1357"},
%Episode{id: "003", post: "280", name: "Pattern Matching", video: "14879", markdown: "1413"},
%Episode{id: "004", post: "284", name: "Functions", video: "5086", markdown: "1559"},
%Episode{id: "005", post: "298", name: "Mix and Modules", video: "5087", markdown: "1654"},
@markevich
markevich / data.yml
Last active July 13, 2016 09:00
Weedlist storefront data
- id: 71274
title: ALL MOONROCKS BOGO GRAM @ $25!!!
body: BOGO GRAM @ $25 ON ALL MOONROCKS ALL DAY!!!
coupon_type: daily
discount_type: bogo
discount_amount:
distance:
value: 7.330996145791065
units: mi
url: "/deals#/709926"