Skip to content

Instantly share code, notes, and snippets.

@psy901
psy901 / binarySearch.java
Created February 5, 2020 10:04
Basic binary search on a sorted list
// "static void main" must be defined in a public class.
public class Main {
public static void main(String[] args) {
int[] arr = {1,2,3,5,10,20,35,100};
int left = 0, right = arr.length - 1;
int target = 4;
while (left <= right) {
int mid = left + (right - left) / 2;
@psy901
psy901 / twoSum.java
Last active December 3, 2019 18:18
LeetCode #2 Two Sum
class Solution {
public int[] twoSum(int[] nums, int target) {
// 1. initialize HashMap for {Number -> Index}
Map<Integer, Integer> map = new HashMap<>();
// 2. iterate the array
for (int i = 0; i < nums.length; i ++) {
// 3. check if such 'num2' exists in the hashmap
int num2 = target - nums[i];
@psy901
psy901 / task1.py
Last active October 22, 2018 19:06
import numpy as np
import csv
import matplotlib.pyplot as plt
from plot_data import plot_data
def plot_data(data):
""" simple plot for x, y """
plt.title('BLE Plot');
# plt.plot([row[0] for row in data], label="x")
@psy901
psy901 / .zshrc
Created February 12, 2018 13:36
my zshrc setup
# If you come from bash you might have to change your $PATH.
export PATH=$PATH:$HOME/bin:/usr/local/bin:~/.composer/vendor/bin:/usr/local/apache-maven/apache-maven-3.3.9/bin:/anaconda/bin
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH="$PATH:$HOME/.rvm/bin"
eval "$(rbenv init -)"
# Path to your oh-my-zsh installation.
export ZSH=/Users/sangyunpark/.oh-my-zsh
@psy901
psy901 / Read_CSV.py
Created January 18, 2018 11:00
Importing columns from csv file
import pandas as pd
def read_csv(filename, num_rows):
# print("")
df = pd.read_csv(filename, encoding='latin-1', nrows=num_rows)
table = df[['Name', 'Country']]
search_terms = []
# getting columns of name and country
@psy901
psy901 / google.py
Created January 18, 2018 06:00
Automated googling with given search term and returning result links
import selenium.webdriver as webdriver
from time import sleep
def get_results(search_term):
MAX_LINKS = 2 # Set the maximum number of links to gather
# Use google to search the search term
url = "https://www.google.com"
browser = webdriver.Chrome()
browser.get(url)
@psy901
psy901 / email.py
Last active January 18, 2018 04:30
With provided URL, it scrawls email addresses within the landing page and the second level pages
import requests
from bs4 import BeautifulSoup
import re
def extract_email_from_url(url):
'''
From the provided url, it extracts all valid email addresses
:param url: URL to enter
:return: Set of email addresses in string
'''
@psy901
psy901 / 0_reuse_code.js
Created March 5, 2017 00:25
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console