Skip to content

Instantly share code, notes, and snippets.

View edwinlab's full-sized avatar
🐢
run

Edwin edwinlab

🐢
run
View GitHub Profile
@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 / 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

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 / 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
#
@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%'
require 'timeout'
def a_method(iterations)
Timeout::timeout(1) do # 1 second
iterations.times { |i| print("#{i} "); sleep(0.1) }
end
rescue Timeout::Error
print("TIMEOUT")
ensure
puts
@edwinlab
edwinlab / union_scope.rb
Created November 7, 2017 08:24 — forked from tlowrimore/union_scope.rb
Unions multiple scopes on a model, and returns an instance of ActiveRecord::Relation.
module ActiveRecord::UnionScope
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def union_scope(*scopes)
id_column = "#{table_name}.#{primary_key}"
sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ")
where "#{id_column} IN (#{sub_query})"
package main
import (
"fmt"
"io"
"os"
)
var path = "/Users/novalagung/Documents/temp/test.txt"
1609-09-12 19:02:35 PM +03:00 Sep Sat PDT 
--------------- + ------------ + ------------ 
Type            | Placeholder  |        Value 
--------------- + ------------ + ------------ 
Year            | 2006         | 1609         
Year            | 06           | 09           
Month           | 01           | 09           
Month           | 1            | 9            
Month           | Jan          | Sep