Skip to content

Instantly share code, notes, and snippets.

:shipit:
shipit

HongHao Zhang honghaoz

:shipit:
shipit
Block or report user

Report or block honghaoz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@honghaoz
honghaoz / NSObject+Observation.swift
Created Apr 21, 2016
Swift KVO handy observation
View NSObject+Observation.swift
//
// NSObject+Observation.swift
// Pods
//
// Created by Honghao Zhang on 2016-02-11.
//
//
import Foundation
@honghaoz
honghaoz / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@honghaoz
honghaoz / collection view perform batch update
Last active Aug 29, 2015
collection view perform batch update
View collection view perform batch update
// Compare old data model with new data model and perform batch update for collection view
/**
* Perform batch update on collection view, use old stories and new stories to make comparison
* groupId property of story is used for comparison
*
* PRE: make sure collection view's data model is update with newArray
*
* After animation completed, visible cells' view are updated
*
View isPrime.py
def isPrime(n):
'''check if integer n is a prime'''
# make sure n is a positive integer
n = abs(int(n))
# 0 and 1 are not primes
if n < 2:
return False
# 2 is the only even prime number
if n == 2:
return True
View kargerMinCut.py
#!/usr/bin/env python
from random import randint
from copy import deepcopy
def find_mincut(n, e):
mincut = len(e)
N = 2000
for x in range(N):
nodes = deepcopy(n)
@honghaoz
honghaoz / LinkedList-RemoveDuplicates.cpp
Created Jun 6, 2014
Remove duplicates from an unsorted linked list
View LinkedList-RemoveDuplicates.cpp
#include<iostream>
#include<set>
using namespace std;
class Node {
public:
int data;
Node *next;
Node(int dat) {
data = dat;
@honghaoz
honghaoz / LinkedList-Basics.cpp
Last active Aug 29, 2015
LinkedList Basic definitions and operations
View LinkedList-Basics.cpp
#include<iostream>
using namespace std;
class Node {
public:
int data;
Node *next;
Node(int dat) {
data = dat;
next = NULL;
View Sort-CountSort.cpp
#include<iostream>
using namespace std;
void countSort(int a[], int size, int k) {
int *b = (int *)malloc(sizeof(int) * k);
memset(b, 0, sizeof(int) * k);
for (int i = 0; i < size; i++) {
b[a[i]]++;
}
for (int i = 1; i < k; i++) {
@honghaoz
honghaoz / String-SamePermutation.cpp
Last active Aug 29, 2015
Check whether one string is a permutation of the other
View String-SamePermutation.cpp
include<set>
include<cstring>
using namespace std;
bool checkSame(string a, string b) {
if (a.length() != b.length()) {
return false;
}
map<char, int> testMap;
int length = (int)a.length();
@honghaoz
honghaoz / String-CheckUniqueCharacters.cpp
Last active Aug 29, 2015
Check whether characters are unique in a string
View String-CheckUniqueCharacters.cpp
#inlcude <cstring>
#include <iostream>
#include <set>
#include <cstring>
using namespace std;
bool checkUniqueChars(char *str) {
char *strP = str;
set<char> testSet;
pair<set<char>::iterator, bool> result;
You can’t perform that action at this time.