Skip to content

Instantly share code, notes, and snippets.

View tsailiming's full-sized avatar

Tsai Li Ming tsailiming

  • Red Hat, Inc.
  • Singapore
  • 10:45 (UTC +08:00)
  • LinkedIn in/tsailiming
View GitHub Profile
@tsailiming
tsailiming / add_aws_provider.rb
Created March 25, 2017 17:52
Sample code to add AWS provider in a service catalog in CloudForms
require 'rest-client'
require 'json'
servername = 'cf'
username = 'admin'
password = 'smartvm'
url = "https://#{servername}/api/providers"
post_params = {
@tsailiming
tsailiming / Screen Shot 2017-03-12 at 11.11.22 PM.png
Last active September 28, 2020 17:00
Configuring ldap with Ansible Tower 3.0.3
Screen Shot 2017-03-12 at 11.11.22 PM.png
@tsailiming
tsailiming / router.sh
Created August 12, 2016 18:55
Add router to openshift enterprise
#!/bin/bash
#http://guifreelife.com/blog/2016/06/16/Deploy-Hawkular-Metrics-in-CDK-2.0-OpenShift-3.1
#https://docs.openshift.com/enterprise/3.2/install_config/install/deploy_router.html
oc project openshift-infra
oc delete all --selector="metrics-infra"
oc delete sa --selector="metrics-infra"
oc delete templates --selector="metrics-infra"
@tsailiming
tsailiming / bootstrap_emr.tf
Created March 13, 2016 16:06
A terraform script to bootstrap EMR.
// EMR is not supported by terraform yet
// https://github.com/hashicorp/terraform/issues/2098
// This script will bootstrap the necessary VPC and related configs first.
provider "aws" {
#access_key = "ACCESS_KEY_HERE"
#secret_key = "SECRET_KEY_HERE"
region = "ap-southeast-1"
}
@tsailiming
tsailiming / Jupyter Configuration for PySpark.ipynb
Last active July 19, 2022 22:33
Jupyter kernel.json configuration for pyspark
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tsailiming
tsailiming / find_pairs.py
Created February 18, 2016 08:07
Given an integer array and a number T, find all *unique* pairs of (a, b) whose sum is equal to T
#!/usr/bin/env python
# Given an integer array and a number T, find all *unique* pairs of (a, b) whose sum is equal to T
# O(n), however is not ordered
def find_pairs(arr, target):
# https://www.ics.uci.edu/~pattis/ICS-33/lectures/complexitypython.txt
# Convert to hash, O(n)
@tsailiming
tsailiming / ec2.rb
Last active March 30, 2017 01:23
My sample ruby script to create an EC2 instance
#!/usr/bin/env ruby
# You will need the following enviromnet variables contiang the your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
# $ env AWS_ACCESS_KEY_ID=<ACCESS_ID> AWS_SECRET_ACCESS_KEY=<SECRET_KEY> ruby ec2.rb
# This creates an instance on AWS using the t2.nano and it will perform the following steps:
# 1. *WARNING* It will remove all existing internet gateways, subnets, vpcs and assiocated resources
# 2. Because t2.nano/micro must be created in a VPC, the internet gateway and security group must be configured:
# http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Scenario1.html
# 3. Wait for the instance to be made available
@tsailiming
tsailiming / benchmark_spark_blas.scala
Created February 10, 2016 08:53
A quick mirobenchmark to benchmark the performance of Native Blas vs f2jblas
import org.apache.spark.mllib.linalg.{Vector, Vectors}
import com.github.fommil.netlib.{BLAS => NetlibBLAS, F2jBLAS}
import com.github.fommil.netlib.BLAS.{getInstance => NativeBLAS}
def time[R](block: => R): R = {
val t0 = System.nanoTime()
val result = block // call-by-name
val t1 = System.nanoTime()
println("Elapsed time: " + (t1 - t0)/1000000.0 + "ms")
result
@tsailiming
tsailiming / mqtt_client.py
Last active August 29, 2015 14:20
Simple paho mqtt client
#/usr/bin/python
import paho.mqtt.publish as publish
from paho.mqtt.client import MQTTv311
import time
for i in xrange(10):
publish.single("testing", time.asctime() + ' hello ' + str(i), hostname="localhost",port=1883,protocol=MQTTv311)