Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Working from home

Mohamed Ziata WaKeMaTTa

💻
Working from home
View GitHub Profile
@WaKeMaTTa
WaKeMaTTa / migration.rb
Last active Apr 17, 2020
Rails migration with foreign key cascade
View migration.rb
class UpdateForeignKey < ActiveRecord::Migration[5.0]
def change
add_reference :posts, :users, index: true, foreign_key: { on_delete: :cascade }
end
end
@WaKeMaTTa
WaKeMaTTa / order-rails-controller-callbacks.md
Last active Jul 29, 2019
Order of Rails Controller Callbacks
View order-rails-controller-callbacks.md

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 / benchmark.rb
Created Feb 5, 2019
Benchmark about "recursive regex match?" vs "recursive my own match?"
View benchmark.rb
require 'bundler/inline'
gemfile(true) do
ruby '~> 2.5'
source 'https://rubygems.org'
gem 'benchmark-ips'
end
require 'benchmark/ips'
View rails_way_counter_cache.rb
# 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 / bug_report_counter_culture.rb
Created Dec 19, 2018
Bug Report - gem counter_culture - Method size don't use the counter cache
View bug_report_counter_culture.rb
# 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"
View spec.rb
# Use TDD principles to build out name functionality for a Person.
# Here are the requirements:
# - Add a method to return the full name as a string. A full name includes
# first, middle, and last name. If the middle name is missing, there shouldn't
# have extra spaces.
# - Add a method to return a full name with a middle initial. If the middle name
# is missing, there shouldn't be extra spaces or a period.
# - Add a method to return all initials. If the middle name is missing, the
# initials should only have two characters.
#
@WaKeMaTTa
WaKeMaTTa / prototype-to-jquery.md
Last active Oct 10, 2018
Converting from Prototype to jQuery (v1)
View prototype-to-jquery.md

Converting from Prototype to jQuery

Selecting DOM elements

Prototype’s selector returns DOM elements.

$("element_id");
// return: <div id="element_id"></div>
@WaKeMaTTa
WaKeMaTTa / md5.log
Last active Jul 24, 2018
md5sum of Arma 3 directory (Ubuntu 16.04 LTS)
View md5.log
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
View capybara_cheat_sheet.md

Navigating

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

Clicking links and buttons

@WaKeMaTTa
WaKeMaTTa / app-policies-application_policy.rb
Created Apr 7, 2017
Use alias_method for better readability
View app-policies-application_policy.rb
# app/policies/application_policy.rb
class ApplicationPolicy
attr_reader :user, :record
def initialize(current_user, record)
@user = user
@record = record
end
end
You can’t perform that action at this time.