Skip to content

Instantly share code, notes, and snippets.

View sgsharma's full-sized avatar
💭
Sleeping

Sasha Sharma sgsharma

💭
Sleeping
View GitHub Profile
@sgsharma
sgsharma / jenkins-slave
Created April 12, 2017 18:09 — forked from jacksoncage/jenkins-slave
Bash script to check if a Jenkins slave node is offline and will restart node java process.
#!/bin/sh
#
# jenkins-slave: Launch a Jenkins BuildSlave instance on this node
#
# chkconfig: - 99 01
# description: Enable this node to fulfill build jobs
#
JENKINS_WORKDIR="/var/jenkins"
JENKINS_USER="jenkins"
@sgsharma
sgsharma / Gemfile
Created May 30, 2018 04:34 — forked from adamsanderson/Gemfile
Demonstration of hierarchical queries in Postgres using a materialized path. It will create a new database that you can later play around with.
source 'https://rubygems.org'
gem 'activerecord', '4.0.0.rc1'
@sgsharma
sgsharma / python_mac.sh
Last active August 30, 2018 18:22
Python3 on Mac
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)";
brew install python;
echo "alias python=python3" >> ~/.bash_profile
echo "alias pip=pip3" >> ~/.bash_profile
@sgsharma
sgsharma / pg_update_with_select.sql
Created August 29, 2018 19:46
Updating PG table with a select query
UPDATE dummy
SET customer=subquery.customer,
address=subquery.address,
partn=subquery.partn
FROM (SELECT address_id, customer, address, partn
FROM /* big hairy SQL */ ...) AS subquery
WHERE dummy.address_id=subquery.address_id;
@sgsharma
sgsharma / list_fkey.sql
Created August 29, 2018 19:47
List all foreign key relationships on a table
SELECT
tc.constraint_name, tc.table_name, kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
@sgsharma
sgsharma / recursive_select.sql
Created August 29, 2018 19:49
Recursive select for all children of parent
SELECT * FROM (WITH RECURSIVE ret as (
SELECT
*
FROM tbl
WHERE
id = 50080
UNION ALL
SELECT
tbl.*
FROM tbl
@sgsharma
sgsharma / emacs_setup.txt
Created August 29, 2018 23:25
Emacs and ESS setup on macOS Sierra
brew install emacs --with-cocoa
curl -O http://ess.r-project.org/downloads/ess/ess-17.11.tgz
brew install r
## Add this to your .emacs file
(add-to-list 'load-path "/Hades/Aeneas/CTX.local/ssharma/source/ess/ess-16.04/lisp")
(load "ess-site")
(split-window-right)
(show-paren-mode 1)
@sgsharma
sgsharma / docker_mac.sh
Created August 31, 2018 04:19
Install docker on MacOS with brew
brew cask install docker
## start with docker.app and login with docker id
@sgsharma
sgsharma / get_columns.sql
Created September 5, 2018 21:47
Get list of column names from table in Postgres
SELECT *
FROM information_schema.columns
WHERE table_name = 'your_table'
@sgsharma
sgsharma / read_only_user_pg.sql
Last active September 6, 2018 18:44
Make a read only user for a PG DB
/*Create role
and grant connect privileges:*/
CREATE ROLE user_read;
GRANT CONNECT ON DATABASE database_name TO user_read;
-- Grant select on all current tables
GRANT SELECT ON ALL TABLES IN SCHEMA schema_name TO user_name;
-- Change default privileges to grant select on all future tables
ALTER DEFAULT PRIVILEGES FOR ROLE user_read IN SCHEMA schema_name GRANT SELECT ON TABLES TO user_read;