Skip to content

Instantly share code, notes, and snippets.

View namuan's full-sized avatar
🎯
Focusing

namuan namuan

🎯
Focusing
View GitHub Profile
#!/usr/bin/env bash
# From: http://blog.slashdeploy.com/2016/03/05/bootstrapping-dns-on-aws/
set -euo pipefail
declare stack_name="dns"
usage() {
echo "${0} COMMAND [options] [arguments]"
@namuan
namuan / python-boilerplate.py
Created June 4, 2017 09:09
Boilerplate for python
#!/usr/bin/env python
# Copied from http://www.oliversherouse.com/2015/08/21/boilerplate.html
"""A boilerplate script to be customized for data projects.
This script-level docstring will double as the description when the script is
called with the --help or -h option.
"""
import com.intellij.database.model.DasTable
import com.intellij.database.model.ObjectKind
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil
/*
* Available context bindings:
* SELECTION Iterable<DasObject>
* PROJECT project
* FILES files helper
@namuan
namuan / rotate_access_keys.txt
Created July 15, 2018 10:31
Rotate AWS access keys
AWSUSERNAME=<aws-user>
AWSPROFILE=<aws-profile>
# Get all the access keys currently used. We'll keep note of the one we are trying to rotate
aws iam list-access-keys --user-name $AWSUSERNAME
# Create a new access key
aws iam create-access-key --user-name $AWSUSERNAME
# Configure using aws-cli with the values generated from the above command
@namuan
namuan / chrome_headless.md
Created August 26, 2018 18:01
Driving Chrome Headless in Docker with Python #chrome #headless #python

Download and run docker image with headless chrome

docker run -d -p 9222:9222 --cap-add=SYS_ADMIN justinribeiro/chrome-headless

That should start up chrome headless on docker-ip:9222

That uses Chrome Remote Dev protocol which is not what selenium implements so we’ll try to use Chromedriver

Unable to find a docker file with a combination of Chrome headless + Latest Chrome driver

@namuan
namuan / saving_crypto_data.md
Created August 26, 2018 18:05
[Saving CryptoCurrency market data in MySQL database] #cryptocurrency #mysql

We are going to use the Bittrex API to get market summary data

curl -X GET "https://bittrex.com/api/v1.1/public/getmarketsummaries" -o market_summaries.json

Each summary item looks like this

 {
@namuan
namuan / get_nat_gateway.md
Last active August 26, 2018 18:08
[AWS: Get Nat Gateway from VPCs] #aws #vpc #nat

To filter VPC Ids

aws ec2 describe-vpcs --filters Name=tag:Name,Values='dev vpc' Name=tag:ServiceName,Values=xyz --query Vpcs[].VpcId

To get public Ips for a given Vpc

aws ec2 describe-nat-gateways --filter Name=vpc-id,Values=vpc-1abc184a --query NatGateways[].NatGatewayAddresses[].PublicIp
@namuan
namuan / java_combinators.java
Created August 26, 2018 18:18
[Combinators] Since Java 8 `static` and `default` methods are allowed within `interface`s.
interface ArtistValidator extends Function<Artist, Optional<Artist>>{
static ArtistValidator hasMailWithAtSign(){
return holds(artist -> artist.email.contains("@"));
}
static ArtistValidator nameIsNotEmpty(){
return holds(artist -> artist.name.trim().length()>0);
}
static ArtistValidator holds(Function<Artist, Boolean> p){
return artist -> p.apply(artist)?Optional.of(artist):Optional.empty();
}
@namuan
namuan / py_data_collector.md
Created August 26, 2018 18:19
[Developing data collector for Response codes] #python #scraping
@namuan
namuan / deleted_file_git.md
Created August 26, 2018 18:30
[Find deleted file in Git] #git #tips
# Find file if we dont have the full path
git log --diff-filter=D --summary | grep delete | grep Sub

# Once we have the full path, this will give log on the file
git log --all --  src/groovy/.../../shared/serialize/Somefile.groovy

# Checkout file / or check with Source tree
git checkout <git-sha-here> src/groovy/.../../shared/serialize/Somefile.groovy