Skip to content

Instantly share code, notes, and snippets.

View WaKeMaTTa's full-sized avatar
✔️
Verified

Mohamed Ziata WaKeMaTTa

✔️
Verified
View GitHub Profile
@WaKeMaTTa
WaKeMaTTa / application_record.rb
Created March 13, 2017 07:59
New way to create models (Rails 5 way):
# app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
@WaKeMaTTa
WaKeMaTTa / app-policies-application_policy.rb
Created April 7, 2017 10:37
Use alias_method for better readability
# app/policies/application_policy.rb
class ApplicationPolicy
attr_reader :user, :record
def initialize(current_user, record)
@user = user
@record = record
end
end
@WaKeMaTTa
WaKeMaTTa / capybara_cheat_sheet.md
Last active May 21, 2018 12:51 — forked from zhengjia/capybara cheat sheet
Capybara - Cheat Sheet

Navigating

visit("/projects")
visit(post_comments_path(post))

Clicking links and buttons

@WaKeMaTTa
WaKeMaTTa / md5.log
Last active July 24, 2018 19:58
md5sum of Arma 3 directory (Ubuntu 16.04 LTS)
04e449fd1e80b8e0d9c4048d3bf93adc ./saferun.sh
8b139ac5b93769623bd343318048238c ./legal/ICU License - ICU 1.8.1 and later.html
2100bdc885ac4cdc9783c562639ddc1f ./legal/OpenSSL.txt
10ec1bb9e39d6056d34cd954e09c6dc7 ./legal/LGPL v2.txt
c5232433d0f75d4f6c7974709fd898cb ./legal/licenses.txt
f094e5cb2db3826da69860d83db6a3b7 ./legal/libpng.txt
beb48b173a776d45fee6dd9b70cb6be7 ./legal/libtiff.txt
db1b7a668b2a6f47b2af88fb008ad555 ./legal/xiph.org.txt
844cfb3cf1a83eedc083c702c8a27f6c ./legal/libmspack.txt
85f70f1acc953dac84b1bd92acb992f3 ./legal/TomCrypt.txt
@WaKeMaTTa
WaKeMaTTa / prototype-to-jquery.md
Last active October 10, 2018 19:27
Converting from Prototype to jQuery (v1)

Converting from Prototype to jQuery

Selecting DOM elements

Prototype’s selector returns DOM elements.

$("element_id");
// return: <div id="element_id"></div>
@WaKeMaTTa
WaKeMaTTa / bug_report_counter_culture.rb
Created December 19, 2018 12:39
Bug Report - gem counter_culture - Method size don't use the counter cache
# frozen_string_literal: true
# Please include only the minimum code necessary to reproduce your issue.
require "bundler/inline"
# STEP ONE: What versions are you using?
gemfile(true) do
ruby "2.5.1"
source "https://rubygems.org"
gem "activerecord", "4.2.11"
@WaKeMaTTa
WaKeMaTTa / rails_way_counter_cache.rb
Created December 20, 2018 11:25
Rails counter cache
# frozen_string_literal: true
# Please include only the minimum code necessary to reproduce your issue.
require "bundler/inline"
# STEP ONE: What versions are you using?
gemfile(true) do
ruby "2.5.1"
source "https://rubygems.org"
gem "activerecord", "4.2.11"
@WaKeMaTTa
WaKeMaTTa / benchmark.rb
Created February 5, 2019 20:06
Benchmark about "recursive regex match?" vs "recursive my own match?"
require 'bundler/inline'
gemfile(true) do
ruby '~> 2.5'
source 'https://rubygems.org'
gem 'benchmark-ips'
end
require 'benchmark/ips'
@WaKeMaTTa
WaKeMaTTa / order-rails-controller-callbacks.md
Last active July 29, 2019 12:29
Order of Rails Controller Callbacks

Order of Rails Controller Callbacks

Rails 4.x

Started GET "/" for 127.0.0.1 at 2017-05-19 14:17:18 +0200
  Processing by WelcomeController#index as HTML
    prepend_around_action
    prepend_before_action
 before_action
@WaKeMaTTa
WaKeMaTTa / migration.rb
Last active April 17, 2020 08:13
Rails migration with foreign key cascade
class UpdateForeignKey < ActiveRecord::Migration[5.0]
def change
add_reference :posts, :users, index: true, foreign_key: { on_delete: :cascade }
end
end