Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jiankuang
jiankuang / ArraysLeftRotation.py
Last active March 17, 2017 16:52
Python Data Structures and Algorithms
def array_left_rotation(a, n, k):
if n == k * 2:
for i in range(k):
a[i+k], a[i] = a[i], a[i+k]
else:
temp = a[0]
i = 0
while True:
if i+k < n:
a[i] = a[i+k]
@jiankuang
jiankuang / ComputeEngine.md
Last active November 29, 2016 19:25
Google Cloud

SSH
gcloud compute ssh jian_kuang@compute-engine-instance-with-bigtable-access
Copy
gcloud compute copy-files Anaconda2-4.2.0-Linux-x86_64.sh jian_kuang@genia-datalab-compute:Anaconda2-4.2.0-Linux-x86_64.sh --zone us-central1-b

@jiankuang
jiankuang / Python.md
Last active March 17, 2017 15:18
Python snippets

split Function

>>> str = "Hello,world,how,are,you"
>>> str.split(",")
['Hello', 'world', 'how', 'are', 'you']
>>> str.split(",")[0]
'Hello'
>>> str.split(",")[1]
'world'
&gt;&gt;&gt; str.split(",", 1)
# import mysql tables into HDFS using sqoop
sqoop import-all-tables --connect jdbc:mysql://localhost/retail_db --username retail_dba --password cloudera
# import mysql tables into hive using sqoop
sqoop import-all-tables --connect jdbc:mysql://localhost/retail_db --username retail_dba --password cloudera --hive-import --create-hive-table
@jiankuang
jiankuang / Binary Tree.md
Last active October 19, 2022 20:48
Data Structures and Algorithms

Binary Tree

Traverse a Tree

 // Definition for a binary tree node.
 class TreeNode {
     val: number
     left: TreeNode | null
     right: TreeNode | null
     constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
         this.val = (val===undefined ? 0 : val)
@jiankuang
jiankuang / index.html
Last active June 4, 2016 01:48
D3 Layout Tree 2
<head>
<style>
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
.node {
font: 10px sans-serif;
}
@jiankuang
jiankuang / index.html
Last active May 31, 2016 18:55
D3 Layout Bubble
<body>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var width = 960, height = 900,
color = d3.scale.category10();
var chart = d3.select("body").append("svg")
.attr("width", width).attr("height", height)
.append("g")
.attr("transform", "translate(50,50)");
@jiankuang
jiankuang / bubblechart.html
Last active May 29, 2016 19:49
D3 Layout Pack
<body>
<nav><ul>
<li><a href="index.html">Pack Layout</a></li>
<li><a href="bubblechart.html">Bubble Layout</a></li>
</ul></nav>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var width = 800, height = 600;
var chart = d3.select("body").append("svg")
@jiankuang
jiankuang / index.html
Last active May 29, 2016 18:52
D3 Layout Tree
<body>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var chart = d3.select("body").append("svg")
.attr("width", 500)
.attr("height", 500)
.append("g")
.attr("transform", "translate(50, 50)");
var tree = d3.layout.tree()
@jiankuang
jiankuang / index.html
Last active May 29, 2016 17:04
D3 Layout Pie Chart
<body>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript">
var data = [10, 50, 80];
var r = 300; // outer radius
var color = d3.scale.ordinal()
.range(["red", "blue", "orange"]);
var svg = d3.select("body").append("svg")