Skip to content

Instantly share code, notes, and snippets.

View mufasa71's full-sized avatar

Shukhrat Mukimov mufasa71

View GitHub Profile
class Page < ActiveRecord::Base
attr_accessible :body, :name, :slug, :image, :destroyed_at
include DestroyedAt
has_attached_file :image
before_destroy :make_backup, prepend: true
before_restore :revert_image
private
def make_backup
class Roulette
def method_missing(name, *args)
person = name.to_s.capitalize
super unless %w[Bob Frank Bill].include? person
number = 0
3.times do
number = rand(10) + 1
puts "#{number}..."
end
"#{person} got a #{number}"
@mufasa71
mufasa71 / mutex.js
Created January 22, 2014 14:15 — forked from oivoodoo/mutex.js
var Mutex = function() {
this.queues = [];
this.locked = false;
};
Mutex.prototype = {
push: function(callback) {
var self = this;
this.queues.push(callback);
if (!this.locked) {
module Reportable
extend ActiveSupport::Concern
module ClassMethods
# Chain on a scope and specify the fields to extract.
# Example:
# User.enabled.report %{
# :email_opt_in,
# 'created_at as sign_up_date'
# }

Throughout this article, I will use Java's Object-Oriented Programming terminologies such as static, private and public.

Pattern 1: Self-construction

This pattern exploits scoping to allow for private and public fields and methods. It is named as Self-construction because the class function (or constructor) has to assign instance methods one by one.

  • <Leader>sr - change word under cursor (global in project)
  • <Leader>ss - change word under cursor
  • <Leader>f - find word under cursor in current buffer (fuzzy logic)
  • ``.` - position of last change
  • ``^` - position of last insert
  • gf - jump to the filename under cursor
  • ^] - jump to the definition
  • m<Upper Letter> - global mark
  • ``[` - jump to begin of selection
  • gp - select paster text
  1. Single Responsibility Principle (SRP) - eliminating duplications and making sure that our pieces are named appropriately and expressively.
  2. Open-Closed Principle (OCP) - isolating knowledge, naturally building only the extension points that truly represent the pieces of system that will change.
  3. Liskov Substitution Principle (LSP) - only extend derived types don't change base behaviours.
  4. Interface Segregation Principle (ISP) - interfaces should be small, focused on a specific use case. Provide a clear, cohesive view of what class does.
  5. Dependency Inversion Principle (DIP) - depend on abstraction rather than

Law of Demeter

A method can access either locally - instantiated variables, parameters in, or instance variables. By exposing the internals of an object, we are spreading structural knowledge.

  • Lines of code per method <= 3
  • No in-method branching statements
  • No primitives across method boundaries
  • No return values. Focus entirely on sending messages to objects
  • Program like it's 1969 😄
  • Object Calisthenics

Movements

  • Ctrl+b - move one char to left
  • Ctrl+f - move one char to right
  • Alt+b - move one word left
  • Alt+f - move one word right
  • Ctrl+a - jump to start of line
  • Ctrl+e - jump to end of line

Copy & Paste

  • Ctrl+u - cut from line start