Skip to content

Instantly share code, notes, and snippets.

View alex-nexus's full-sized avatar

Alex Chen alex-nexus

  • san francisco bay area
View GitHub Profile
@alex-nexus
alex-nexus / postgres_queries_and_commands.sql
Created July 12, 2017 05:25 — 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%'
@alex-nexus
alex-nexus / keybase.md
Created January 19, 2016 21:32
keybase.md

Keybase proof

I hereby claim:

  • I am alex-nexus on github.
  • I am alexchen (https://keybase.io/alexchen) on keybase.
  • I have a public key whose fingerprint is A94E D302 70D7 4D9C 3362 F913 5F35 93BC 57D9 A5A7

To claim this, I am signing this object:

from decimal import Decimal
from random import random
from time import time
fs = []
ds = []
for i in range(1000000):
rn = random()
fs.append(float(rn))
ds.append(Decimal(rn))
@alex-nexus
alex-nexus / application.rb
Last active August 29, 2015 14:26
Rails CORS middleware
# It’s worth noting that the UI now will not be served by rails, it might even sit in a different server. There are solution that let us keep both UI and API on the same domain, but for now we will need to enable Cross-origin resource sharing (CORS).
# We can do this by adding the rack-cors gem to our Gemfile and then add this in our config/application.rb:
config.middleware.insert_before 'Rack::Runtime', 'Rack::Cors' do
allow do
origins '*'
resource '*',
headers: :any,
methods: [:get, :put, :post, :patch, :delete, :options]
end
@alex-nexus
alex-nexus / gist:ffc6fb7623a1dfd79b08
Created June 21, 2015 06:44
ionic start myApp tabs
○ → ionic start myApp tabs
Creating Ionic app in folder /Volumes/Work/hybrid/myApp based on tabs project
Downloading: https://github.com/driftyco/ionic-app-base/archive/master.zip
[=============================] 100% 0.0s
Downloading: https://github.com/driftyco/ionic-starter-tabs/archive/master.zip
[=============================] 100% 0.0s
Updated the hooks directory to have execute permissions
Update Config.xml
Initializing cordova project
Adding in iOS application by default
@alex-nexus
alex-nexus / Dockerfile
Created May 31, 2015 04:58
sample Dockerfile
FROM ruby:2.2.2
#################################
# native libs
#################################
RUN apt-get update -qq && apt-get install -y build-essential
# for postgres
RUN apt-get install -y libpq-dev
@alex-nexus
alex-nexus / gist:4b63d5de7459b261d810
Created April 29, 2015 22:35
Python datetime / time conversions
from datetime import datetime
import time
#-------------------------------------------------
# conversions to strings
#-------------------------------------------------
# datetime object to string
dt_obj = datetime(2008, 11, 10, 17, 53, 59)
date_str = dt_obj.strftime("%Y-%m-%d %H:%M:%S")
@alex-nexus
alex-nexus / db.rake
Last active August 29, 2015 14:18 — forked from hopsoft/db.rake
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
class PagesController < ApplicationController
before_filter :login_required, :except => [ :show ]
# GET /pages
# GET /pages.xml
def index
@pages = Page.find(:all)
respond_to do |format|
format.html # index.html.erb
@alex-nexus
alex-nexus / gist:7702896
Created November 29, 2013 08:25
module include and extend
class UserSubscription < ActiveRecord::Base
require_dependency 'user_subscription/sendhub'
include UserSubscription::Sendhub
attr_accessible :email, :is_active, :phone, :remind_hour, :remind_minute, :sms_id
belongs_to :user
before_validation :normalize_phone
def normalize_phone