This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the Istio prometheus pod name | |
PROMETHEUS_POD=$(kubectl get pods -n istio-system --selector=app.kubernetes.io/name=prometheus -o name) | |
echo ${PROMETHEUS_POD:?} | |
# forward prometheus API since curl isn't available on the pod | |
kubectl port-forward -n istio-system ${PROMETHEUS_POD:?} 9090:9090 | |
# in a new terminal | |
curl http://localhost:9090/api/v1/query?query=up | jq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: https://www.git-tower.com/learn/git/faq/change-author-name-email | |
# Used this to transfer authorship from an old github account to a new one. | |
git filter-branch --env-filter ' | |
WRONG_EMAIL="wrong@example.com" | |
NEW_NAME="New Name Value" | |
NEW_EMAIL="correct@example.com" | |
if [ "$GIT_COMMITTER_EMAIL" = "$WRONG_EMAIL" ] | |
then | |
export GIT_COMMITTER_NAME="$NEW_NAME" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type RandomizedSet struct { | |
vStack []int | |
// maps key to the index in keyStack | |
vMap map[int]int | |
} | |
func Constructor() RandomizedSet { | |
return RandomizedSet { | |
vStack: []int{}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sumZero(n int) []int { | |
nums := make([]int, n)[0:0] | |
if n % 2 == 1 { | |
nums = append(nums, 0) | |
} | |
n /= 2 | |
for n > 0 { | |
nums = append(nums, -n) | |
nums = append(nums, n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type OrderedStream struct { | |
index int | |
values []string | |
} | |
func Constructor(n int) OrderedStream { | |
return OrderedStream { | |
index: 0, | |
values: make([]string, n), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://en.wikipedia.org/wiki/Quicksort | |
// with upper pivot selection | |
public static void quickSort(int[] nums) { | |
qsSub(nums, 0, nums.length-1); | |
} | |
private static void qsSub(int[] nums, int lo, int hi) { | |
// base-case | |
if (lo >= hi) { | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in-line recursive merge sort | |
public static void mergeSort(int[] nums) { | |
subMergeSort(nums, 0, nums.length-1, new int[nums.length]); | |
} | |
private static void subMergeSort(int[] nums, int start, int end, int[] swap) { | |
if (start == end) { | |
return; | |
} | |
// sort sub-lists | |
int pivot = (start + end) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fullJustify(words []string, maxWidth int) []string { | |
// breakup input words into groups that | |
// won't exceed max width once spaces are added | |
lines := [][]string{} | |
lineWords := []string{} | |
width := 0 | |
for _, word := range words { | |
// start new line if word cant fit on the current line | |
if maxWidth - width - len(lineWords) < len(word) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* type TreeNode struct { | |
* Val int | |
* Left *TreeNode | |
* Right *TreeNode | |
* } | |
*/ | |
func findLeaves(root *TreeNode) [][]int { | |
leaves := [][]int{} |
NewerOlder