Skip to content

Instantly share code, notes, and snippets.

Avatar

Surendran surendrans

View GitHub Profile
@surendrans
surendrans / clean_code.md
Created Jun 30, 2021 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin
View clean_code.md

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
surendrans / rails5_or.rb
Last active Oct 13, 2017
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
surendrans / selectall.js
Created May 3, 2017
Select and Dselect
View selectall.js
$(function(){
// add multiple select / deselect functionality
$("#selectall").click(function () {
$('.case').attr('checked', this.checked);
});
// if all checkbox are selected, check the selectall checkbox
// and viceversa
$(".case").click(function(){
View selenium-webdriver-cheatsheet.md

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
View multiple_ssh_setting.md

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 "your_email@youremail.com"
@surendrans
surendrans / multi_checkbox.erb
Last active Aug 29, 2015
Multiple check box with has many
View multi_checkbox.erb
<%= form_for(@user) do |f| %>
<div class="user_container">
<%= f.label :intrests %>
<ul>
<% Interest.all.each do |interest| %>
<li>
<label class="li">
<%= check_box_tag :intrest_ids, intrest.id, @user.interests.include?(interest), :name => 'user[intrest_ids][]' %> <u><%= intrest.title %></u>
</label>
View capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
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 = WEBrick::HTTPServer.new(:Port => 8080, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"
$ open "http://localhost:8080/viz.html"
View unicorn_init.sh
#!/bin/sh
### BEGIN INIT INFO
# 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.
### END INIT INFO
View unicorn
#!/bin/sh
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:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/path/to/your/app/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENVIRONMENT=production