Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Pythoning, Japanesing

Yoko Harada yokolet

🏠
Pythoning, Japanesing
View GitHub Profile
View budget_instance.sh
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 Oct 20, 2019
Create GCP Instance
View create_instance.sh
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 \
View CBTInserter.java
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;
View CBTCheck.java
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;
View CBTNodeCount.java
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; }
View CatalanNumbers.java
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) {
View PrimeNumber.java
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++) {
View phone_number.clj
;; 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
katakana transcription
View kata_transcription.py
# 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 Oct 18, 2018
Longest Substring with At Most K Distinct Characters
View length_of_longest_substring_k_distinct.py
"""
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
You can’t perform that action at this time.