Skip to content

Instantly share code, notes, and snippets.

View junjaytan's full-sized avatar

Junjay Tan junjaytan

View GitHub Profile
@junjaytan
junjaytan / lisp-examples.lisp
Created September 1, 2017 04:23
Lisp examples
;; create a list
(list 1 2 3)
;; Use getf on a plist (property list) to get an item
(getf (list :a 1 :b 2 :c 3) :a)
;; create a function that takes 4 fields as arguments and returns a plist representing that CD.
(defun make-cd (title artist rating ripped)
(list :title title :artist artist :rating rating :ripped ripped))
;; call that function
@junjaytan
junjaytan / terraform_commands.sh
Created April 20, 2017 06:02
Terraform Commands
# creating
see plan: >> terraform plan
create resources: >> terraform apply
# destroying
see plan: >> terraform plan -destroy
destroy: >> terraform destroy
@junjaytan
junjaytan / aws_cli.sh
Created April 20, 2017 05:53
AWS cli commands
# ec2
aws ec2 describe-instances
@junjaytan
junjaytan / git_commands.sh
Created March 4, 2017 22:11
Misc Git commands
### Deleting branches ####
# delete local branch
git branch -d branch_name
# The -d option is an alias for --delete, which only deletes the branch if it has
# already been fully merged in its upstream branch. You could also use -D,
# which is an alias for --delete --force, which deletes the branch "irrespective of its merged status."
# delete remote branch: two commands you can use
git push origin --delete <branch_name>
git push origin :<branch_name>
@junjaytan
junjaytan / python_yaml_io.py
Created February 24, 2017 22:37
Python Yaml read
"""
For example, if your yaml file is:
- mysite:
url: www.hello.com
username: blah
pw: blah
# local temp directory for storing data
- local_temp_dir: '/my/temp/dir/'
"""
@junjaytan
junjaytan / python_path_manipulations.py
Last active February 21, 2017 05:16
Python path manipulations
# To get the first directory in a path, e.g., return "First" for path /First/Second/Third/file.txt
# there is no easy way to do this using the os.path utilities. Instead, use pathlib
# see: http://stackoverflow.com/questions/26724275/removing-the-first-folder-in-a-path
import pathlib2
mypath='/first-dir/second-dir/third-dir'
p = pathlib2.Path(mypath)
firstdir = p[2] # first element is the '/'. If you don't have a root '/', then the first element is the first dirname
subdirs = p[3:]
@junjaytan
junjaytan / python_boto3.py
Last active February 20, 2017 20:56
Python Boto3 Examples
"""
see: http://boto3.readthedocs.io/en/latest/reference/services/s3.html
set up your aws credentials in ~/.aws/credentials and default region per instructions
here: https://github.com/boto/boto3
"""
s3 = boto3.resource('s3')
# List objects within bucket prefix paths
my_bucket = s3.Bucket('base-bucket-name')
@junjaytan
junjaytan / shell_validate_input_args.sh
Created February 11, 2017 21:04
shell script with simple input args validation
#!/usr/bin/env bash
# DATA_PATH should be the path to the dir holding your input data, e.g., "/mnt/data/"
# THREADS should be an integer
DATA_PATH=$1
THREADS=$2
VSQL_BIN="/opt/vertica/bin/vsql"
import logging
import argparse
def testfunc():
logging.info("This is a log message.")
if __name__ == "__main__":
parser.add_argument('--log', dest='loglevel', required=False, type=str, default='DEBUG',
help='logging level. By default is debug.')
@junjaytan
junjaytan / find_find_by_oldest_date.py
Created January 3, 2017 21:38
Python find file by oldest date
__author__ = 'junjaytan'
"""
A simple script to detect if any files exist in a destination directory. If no files exist, then it finds
the oldest file from an input directory and moves it to the destination directory.
This functionality is useful if you want to ensure that input records get added to a directory in the
same order they were created
"""
import os
import shutil