Skip to content

Instantly share code, notes, and snippets.

@ashishtajane
ashishtajane / MySQL summary
Last active August 29, 2015 14:02
MySQL summary
-- Creation
create table <tablename> (A1 D1,
A2 D2 not null,
primary key (A1),
foreign key (A2)refrences <tablename>)
create table temp_account like account
insert into <tablename> value ('','');
@ashishtajane
ashishtajane / Ubuntu Setup
Last active April 30, 2020 13:19
Ubuntu Setup Script
## Google Chrome
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
## Synaptic Package Manager
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install synaptic
# Install Git, RVM and NodeJS/NPM
sudo apt-get install git-core build-essential make curl
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements
rvm install ruby
rvm use ruby --default
@ashishtajane
ashishtajane / django urlpattern list .py
Last active May 13, 2024 02:08
Get all URL patterns in django
# Open django shell and do following.
import urls
def show_urls(urllist, depth=0):
for entry in urllist:
print(" " * depth, entry.regex.pattern)
if hasattr(entry, 'url_patterns'):
show_urls(entry.url_patterns, depth + 1)
# Using the `@property` decorator allows the MongoEngine Document object to have
# properties that reference Models, and be got/set like normal foreign keys.
# This same pattern can work the other way and allow Models interface with
# Documents.
class Foo(mongoengine.Document):
# The `id` of the property is stored in the Document.
user_id = mongoengine.IntField()
# Setters and getters to interface with the SQL DB and set Users to the
@ashishtajane
ashishtajane / commit-msg
Last active September 23, 2015 11:14 — forked from EmmanuelOga/commit-msg
commit-msg hook to add a prefix to commit messages
#!/usr/bin/env ruby
# Adapted from
# https://gist.github.com/EmmanuelOga/2926764
# Convert a message to include branch name information.
class Transmogrifier < Struct.new(:message, :branchname)
NOREF_MATCHER = /#noref/
BRANCHES_TO_SKIP = ['master', 'develop', 'staging']
PREFIX_MATCHER = /\A([a-zA-Z]+[-_]\d+)[-_]/
@ashishtajane
ashishtajane / base_controller.rb
Created October 17, 2015 19:23 — forked from dhoelzgen/base_controller.rb
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
@ashishtajane
ashishtajane / bs3-login-form.html
Created December 23, 2015 13:56 — forked from bMinaise/bs3-login-form.html
Bootstrap 3 - Login Form Example From: http://bootsnipp.com
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<h1 class="text-center login-title">Sign in to continue to Bootsnipp</h1>
<div class="account-wall">
<img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=120"
alt="">
<form class="form-signin">
<input type="text" class="form-control" placeholder="Email" required autofocus>
<input type="password" class="form-control" placeholder="Password" required>
@ashishtajane
ashishtajane / pagination.md
Created February 2, 2016 12:43 — forked from mislav/pagination.md
"Pagination 101" by Faruk Ateş

Pagination 101

Article by Faruk Ateş, [originally on KuraFire.net][original] which is currently down

One of the most commonly overlooked and under-refined elements of a website is its pagination controls. In many cases, these are treated as an afterthought. I rarely come across a website that has decent pagination, and it always makes me wonder why so few manage to get it right. After all, I'd say that pagination is pretty easy to get right. Alas, that doesn't seem the case, so after encouragement from Chris Messina on Flickr I decided to write my Pagination 101, hopefully it'll give you some clues as to what makes good pagination.

Before going into analyzing good and bad pagination, I want to explain just what I consider to be pagination: Pagination is any kind of control system that lets the user browse through pages of search results, archives, or any other kind of continued content. Search results are the o

@ashishtajane
ashishtajane / model_extension.rb
Created November 7, 2017 11:18 — forked from brenes/model_extension.rb
Removing validation of a model declared on a gem
# We have to remove validations on email, as it's no longer needed.
# Based on a solution found at http://stackoverflow.com/questions/7545938/how-to-remove-validation-using-instance-eval-clause-in-rails
Model.class_eval do
_validators.reject!{ |key, _| key == :field }
_validate_callbacks.each do |callback|
callback.raw_filter.attributes.delete :field
end