Skip to content

Instantly share code, notes, and snippets.

View surendrans's full-sized avatar

Surendran surendrans

View GitHub Profile
surendrans /
Created June 30, 2021 12:09 — forked from wojteklu/
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.

General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

surendrans / rails5_or.rb
Last active October 13, 2017 09:23
rails5 or condition
View rails5_or.rb
User.where(gender: 'M').or("age > 22")
#SELECT "users".* FROM "users" WHERE ("users"."gender" = ? OR "users"."age" > ?) [["gender", 'M'], ["age", "22"]]
User.where(gender: 'M').or(user.where("age > 22"))
#SELECT "users".* FROM "users" WHERE ("users"."gender" = ? OR "users"."age" > ?) [["gender", 'M'], ["age", "22"]]
surendrans / selectall.js
Created May 3, 2017 12:13
Select and Dselect
View selectall.js
// add multiple select / deselect functionality
$("#selectall").click(function () {
$('.case').attr('checked', this.checked);
// if all checkbox are selected, check the selectall checkbox
// and viceversa

API workthough

  1. Open a browser

    # start an instance of firefox with selenium-webdriver
    driver = Selenium::WebDriver.for :firefox
    # :chrome -> chrome
    # :ie     -> iexplore
  • Go to a specified URL

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C ""
surendrans / multi_checkbox.erb
Last active August 29, 2015 14:22
Multiple check box with has many
View multi_checkbox.erb
<%= form_for(@user) do |f| %>
<div class="user_container">
<%= f.label :intrests %>
<% Interest.all.each do |interest| %>
<label class="li">
<%= check_box_tag :intrest_ids,, @user.interests.include?(interest), :name => 'user[intrest_ids][]' %> <u><%= intrest.title %></u>
View capybara cheat sheet
=Clicking links and buttons=
click_link('Link Text')
click('Link Text') # Click either a link or a button
click('Button Value')
View rails-routes-visualizer.txt
$ rails r 'File.write("./viz.html", Rails.application.routes.router.visualizer)'
$ ruby -r webrick -e "s = => 8080, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"
$ open "http://localhost:8080/viz.html"
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
surendrans / unicorn
Last active August 29, 2015 14:14 — forked from shapeshed/unicorn
View unicorn
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app: