Skip to content

Instantly share code, notes, and snippets.

View sourabh-upadhyay's full-sized avatar
🎯
Focusing

Sourabh Upadhyay sourabh-upadhyay

🎯
Focusing
View GitHub Profile
@sourabh-upadhyay
sourabh-upadhyay / find_in_array.go
Created April 13, 2020 11:50
Find the element in an array in golang
package main
import "fmt"
import "reflect"
func contains(val interface{}, array interface{}) (exists bool, index int) {
exists = false
index = -1
switch reflect.TypeOf(array).Kind() {
@sourabh-upadhyay
sourabh-upadhyay / interview_ques.md
Last active May 28, 2018 07:38
Interview questions

decorators

concerns

Rails features (4 & 5)

Blocks

When to use lambda

@sourabh-upadhyay
sourabh-upadhyay / permissions_cheat.md
Last active July 27, 2017 16:21
Permission on linux
Number Octal Permission Representation Ref
0 No permission ---
1 Execute permission --x
2 Write permission -w-
3 Execute and write permission: 1 (execute) + 2 (write) = 3 -wx
4 Read permission r--
5 Read and execute permission: 4 (read) + 1 (execute) = 5 r-x
6 Read and write permission: 4 (read) + 2 (write) = 6 rw-
7 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 rwx
@sourabh-upadhyay
sourabh-upadhyay / install-aws-cli.md
Last active December 8, 2017 12:32
Install AWS CLI in Ubuntu
  1. Install AWS CLI using the OS X Bundled Installer.

python --version

  1. Now download the AWSCLI installer using the following command:

curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

  1. Unzip the package

unzip awscli-bundle.zip

  1. Run the install executable and test the AWS CLI installation

sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

  1. Configure AWS credentials
@sourabh-upadhyay
sourabh-upadhyay / eager_load_with_alias_attr.rb
Last active March 29, 2017 13:04
Alias attribute with eager loading in rails
#Simple monkey patch would work
module ActiveRecord
Base.send :attr_accessor, :_row_
module Associations
class JoinDependency
JoinBase && class JoinPart
def instantiate_with_row(row, *args)
instantiate_without_row(row, *args).tap { |i| i._row_ = row }

Key features of Assets pipeline

  1. Concatenate assets (Which can reduce the number of requests that a browser makes to render a web page) (Sprockets concatenates all JavaScript files into one master .js file and all CSS files into one master .css file)
  2. Asset minification or compression
  3. Coding assets via a higher level languages (SASS for CSS, CoffeeScript for JS, and ERB for both by default)

What is Fingerprinting and Why Should I Care?

@sourabh-upadhyay
sourabh-upadhyay / sublime-linter-with-rubocop.md
Created February 24, 2017 05:28
Install linter with Rubocop in Sublime

In order to enable rubocop for your sublime package 3 you first need to make sure the control package of sublime is installed on your sublime package. To check for the control package Way 1: Step 1 -> open sublime package 3 and press ctrl + shift + p wait for some time (hardly 5 seconds) it will open a text field in the sublime package. Step 2 -> Type install if you see Package Control : Install package then the control package is install.

@sourabh-upadhyay
sourabh-upadhyay / .bashrc
Last active May 24, 2017 11:19
Show git branch name on ubuntu terminal/console
## Show current git branch on terminal
#### Add this line of code at the end on file *.bashrc* in Home directory
export GIT_PS1_SHOWDIRTYSTATE=1
export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[00;31m\]$(__git_ps1)\[\033[00;34m\] \$\[\033[00m\] '