Skip to content

Instantly share code, notes, and snippets.

View yokolet's full-sized avatar
🏠
Doing Rails dev now

Yoko Harada yokolet

🏠
Doing Rails dev now
View GitHub Profile
export INSTANCE_NAME="my-tf2-instance"
export ZONE="us-central1-c"
export IMAGE_FAMILY="tf2-latest-gpu"
export INSTANCE_TYPE="n1-highmem-4"
export ACCELERATOR="type=nvidia-tesla-k80,count=1"
gcloud compute instances create $INSTANCE_NAME \
--zone=$ZONE \
--image-family=$IMAGE_FAMILY \
--image-project=deeplearning-platform-release \
@yokolet
yokolet / create_instance.sh
Created October 20, 2019 06:18
Create GCP Instance
export IMAGE_FAMILY="tf2-latest-gpu" # or "tf2-latest-cpu" for non-GPU instances
export ZONE="us-west1-b" # budget: "us-west1-b", richer: us-west2-b
export INSTANCE_NAME="my-tf2-instance"
export INSTANCE_TYPE="n1-highmem-4" # budget: "n1-highmem-4", richer: n1-highmem-8
# budget: type=nvidia-tesla-k80,count=1
# richer: type=nvidia-tesla-p4,count=1
export ACCELERATOR="type=nvidia-tesla-k80,count=1"
gcloud compute instances create $INSTANCE_NAME \
--zone=$ZONE \
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class CBTInserter {
private TreeNode root = null;
private List<TreeNode> memo = new ArrayList<>();
public CBTInserter(TreeNode root) {
this.root = root;
public class CBTCheck {
private int[] walk(TreeNode root) {
if (root == null) { return new int[]{0, 0, 1}; } // min, max, valid
int[] left = walk(root.left);
int[] right = walk(root.right);
int valid = left[2] & right[2];
if (right[1] > left[1]) {
valid = 0;
} else if (right[1] + 1 < left[1]) {
valid = 0;
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
public class CBTNodeCount {
private int getHeight(TreeNode root) {
if (root == null) { return 0; }
public class CatalanNumbers {
public int numPatterns(int n) {
double count = 1.0;
for (double i = 1.0; i <= n; i += 1.0) {
count *= ((i + n) / i);
}
return (int) Math.round(count / (n + 1));
}
public int numPatternsDP(int n) {
import java.util.*;
public class PrimeNumber {
private List<Integer> sieve(int m) {
List<Integer> p = new ArrayList<Integer>();
if (m <= 1) { return p; }
boolean[] ary = new boolean[m+1];
Arrays.fill(ary, 2, m+1, true);
for (int i = 2; i <= m; i++) {
;; A solution and test code for https://www.hackerrank.com/challenges/30-dictionaries-and-maps/problem
;; test/thirty-days-code.core_test.clj
(ns thirty-days-code.core-test
(:require [clojure.java.io :as io]
[clojure.test :refer :all]))
(defn wrap-test [n f]
(with-open [rdr (io/reader (io/resource n))]
(binding [*in* rdr]
@yokolet
yokolet / kata_transcription.py
Last active May 20, 2019 04:50
katakana transcription
# https://en.wikibooks.org/wiki/Japanese/Transcribing_English_to_Japanese
import os
import sys
sys.path.append(os.path.abspath('./English-to-IPA'))
from pykakasi import kakasi
import romkan
import eng_to_ipa as ipa
import re
@yokolet
yokolet / length_of_longest_substring_k_distinct.py
Created October 18, 2018 20:21
Longest Substring with At Most K Distinct Characters
"""
Description:
Given a string, find the length of the longest substring T that contains at most k
distinct characters.
Examples:
Input: s = "eceba", k = 2
Output: 3 -- 'ece' is the longest
Input: s = "aa", k = 1