Skip to content

Instantly share code, notes, and snippets.

View bao-qian's full-sized avatar
🎯
Focusing

bao-qian

🎯
Focusing
View GitHub Profile
@bao-qian
bao-qian / test.hs
Last active March 11, 2016 00:08
test
data Node = Node String deriving (Eq, Ord, Show)
data Graph = Graph (M.Map Node [Edge]) deriving (Eq, Show)
emptyGraph = Graph M.empty
nodes (Graph g) = M.keys g
edges (Graph g) = concat (M.elems g)
s2n = Node
n2s (Node n) = n
insertNode n (Graph g) = Graph (M.insert n [] g)
insertEdge e@(s, _, _) (Graph g) = Graph (M.adjust (e:) s g)
#cloud-config
users:
- default
- name: stack
lock_passwd: False
sudo: ["ALL=(ALL) NOPASSWD:ALL\nDefaults:stack !requiretty"]
shell: /bin/bash
write_files:
@bao-qian
bao-qian / galaxy_price.py
Last active September 13, 2015 01:56
galaxy_price
# use python3
from collections import deque
ROMAN_ARABIC_DICT = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
DIRT_DICT = {}
METAL_DICT = {}
MSG = "I have no idea what you are talking about"
def parse_galaxy_numerals(galaxy_numerals: list) -> int:
@bao-qian
bao-qian / Microsoft.PowerShell_profile.ps1
Created September 19, 2015 21:17
My powershell profile
# Load posh-git module from current directory
Import-Module posh-git
# Get full name of user
$username = [Environment]::UserName
$hostname = $env:COMPUTERNAME
# Am I an admin?
$wid = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp = new-object System.Security.Principal.WindowsPrincipal($wid)
@bao-qian
bao-qian / pi.md
Last active November 1, 2024 07:51
programming introduction
@bao-qian
bao-qian / question_2.py
Last active July 18, 2017 03:40
question_2.py
# -*- coding: utf-8 -*-
# Please use Python 3
# Please run it with python3 -m doctest xxx.py
def flatten(nested_list: list) -> list:
"""
>>> flatten([])
[]
>>> flatten([[[[]],[]]])
@bao-qian
bao-qian / question_3.py
Last active July 18, 2017 03:40
question_3.py
# -*- coding: utf-8 -*-
# Please use Python 3
# Please run it with python3 -m doctest xxx.py
import json
from math import sin, cos, acos, fabs, radians
import requests
@bao-qian
bao-qian / KeyValueStore.h
Last active December 18, 2015 01:03
Key Value Store Declaration
#import <Foundation/Foundation.h>
@interface Table : NSObject
- (id)init:(NSString *)name
+ (BOOL)isExists:(NSString *)name
- (void)clear
package codeTest;
import java.util.Collection;
import java.util.Iterator;
/**
* Implement an iterator that iterates all the elements of a collection of collections
*/
public class CodeTestExerciseCollectionOfCollectionsIterator implements Iterator<Object> {
@bao-qian
bao-qian / CodeTestExerciseBadCode.java
Last active March 2, 2016 12:56
Exercise Bad Code
package codeTest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;