Skip to content

Instantly share code, notes, and snippets.

View surendrans's full-sized avatar

Surendran surendrans

View GitHub Profile
@surendrans
surendrans / clean_code.md
Created June 30, 2021 12:09 — forked from wojteklu/clean_code.md
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
surendrans / rails5_or.rb
Last active October 13, 2017 09:23
rails5 or condition
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 12:13
Select and Dselect
$(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(){

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 "your_email@youremail.com"
@surendrans
surendrans / multi_checkbox.erb
Last active August 29, 2015 14:22
Multiple check box with has many
<%= 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>
=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')
$ 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"
#!/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
@surendrans
surendrans / unicorn
Last active August 29, 2015 14:14 — forked from shapeshed/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