Skip to content

Instantly share code, notes, and snippets.

View chrislzm's full-sized avatar

Chris Leung chrislzm

View GitHub Profile
@chrislzm
chrislzm / problems-strings-20170511-1.java
Last active May 11, 2017 21:19
Coding Problem (Strings)
static int getMaxStrLen(String s) {
Set<Character> chars = new HashSet<> ();
char[] cArray = s.toCharArray();
for (char c : cArray) {
if (!chars.contains(c)) {
chars.add(c);
}
}
if (chars.size() < 2)
return 0;
@chrislzm
chrislzm / problems-strings-20170511-2.java
Created May 11, 2017 21:18
Coding Problem (Strings)
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int q = in.nextInt();
for(int a0 = 0; a0 < q; a0++) {
String s = in.next();
boolean valid = false;
long firstx = -1;
// Try each possible starting number
for (int i=1; i<=s.length()/2; ++i) {
long x = Long.parseLong(s.substring(0,i));
@chrislzm
chrislzm / mapViewPolyLine.swift
Created May 23, 2017 02:05
Drawing a poly line on a mapview in Swift 3
func somewhereElse() {
let startLocation = CLLocation(latitude: startLat, longitude: startLon)
let endLocation = CLLocation(latitude: endLat, longitude: endLon)
let locations = [startLocation,endLocation]
var coordinates = locations.map({(location: CLLocation!) -> CLLocationCoordinate2D in return location.coordinate})
let polyline = MKPolyline(coordinates: &coordinates, count: locations.count)
mapView.add(polyline)
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
@chrislzm
chrislzm / System Design.md
Created November 12, 2017 05:27 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
class PaginateListings {
static class Listing {
Float score;
String hostId;
String listing;
Listing(float s, String h, String l) {
score = s;
hostId = h;
listing = l;