Skip to content

Instantly share code, notes, and snippets.

View edwinlab's full-sized avatar
🐢
run

Edwin edwinlab

🐢
run
View GitHub Profile
@edwinlab
edwinlab / postgres_queries_and_commands.sql
Created October 4, 2017 08:31 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@edwinlab
edwinlab / active_record.rb
Last active September 15, 2017 03:00
Custom find with date range to handle table partition
module ActiveRecord
class Base
class << self
#
# SELECT "payments".*
# FROM "payments"
# WHERE "payments"."id" = <id>
# AND ("payments"."created_at" BETWEEN '<start month>' AND '<end month>')
# ORDER BY "payments"."id" ASC LIMIT 1
#

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
@edwinlab
edwinlab / readme-template.md
Last active July 27, 2017 06:44
Readme template

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@edwinlab
edwinlab / AppBar.java
Created May 14, 2017 09:07
app bar addOnOffsetChangedListener
AppBarLayout appBar = (AppBarLayout) rootView.findViewById(R.id.app_bar);
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
}
});
@edwinlab
edwinlab / filter.rb
Created April 26, 2017 07:04
filter using join model on has_many through
class Person
has_many :accounts
has_many :computers, through: :accounts
end
class Account
belongs_to :person
belongs_to :computer
scope :administrators, -> { where(role: 'administrator') }
module Validate
class Activity
include ActiveModel::Validations
attr_accessor :latitude, :longitude
validates :latitude, presence: true, numericality: true
validates :longitude, presence: true, numericality: true
def initialize(params={})
def self.escape_characters_in_string(string)
pattern = /(\'|\"|\.|\*|\/|\-|\\|\)|\$|\+|\(|\^|\?|\!|\~|\`)/
string.gsub(pattern){|match|"\\" + match}
end