Skip to content

Instantly share code, notes, and snippets.

View Harryyan's full-sized avatar
🏠
Working from home

Harry Harryyan

🏠
Working from home
View GitHub Profile
@Harryyan
Harryyan / Heap.swift
Created January 22, 2022 20:13
Heap Data Structure in Swift
struct Heap<T> {
var nodes = [T]()
private var orderCriteria: (T, T) -> Bool
init(sort: @escaping (T, T) -> Bool, array: [T]) {
orderCriteria = sort
heapify(array: array)
}
@Harryyan
Harryyan / DeleteFiles.m
Last active November 12, 2021 20:46
Using Stack DFS to optimize file recursion (Objective C)
- (void)mnz_removeFolderContentsRecursivelyAtPath:(NSString *)folderPath forItemsExtension:(NSString *)itemsExtension {
NSArray *directoryContentsArray = [self contentsOfDirectoryAtPath:folderPath error:nil];
NSString *currentPath = folderPath;
NSEnumerator *enumerator = [directoryContentsArray objectEnumerator];
NSMutableArray *stack = [NSMutableArray array];
if (enumerator) {
[stack addObject:enumerator];
}
@Harryyan
Harryyan / Practice.swift
Created June 14, 2017 22:33
Swift flatmap, map, filter, reduce prractice
//: Playground - noun: a place where people can play
import UIKit
// Map
let fruits0 = ["apple", "banana", "orange", ""]
let counts0 = fruits0.map { fruit0 -> Int? in
let length = fruit0.characters.count
guard length > 0 else {
return nil
extension String{
//下标属性
subscript(subrange: Range<Int>) -> String {
get {
var start = advance(startIndex, subrange.startIndex)
var end = advance(startIndex, subrange.endIndex)
return substringWithRange(Range(start: start, end: end))
@Harryyan
Harryyan / keywordtest
Created April 26, 2014 05:47
模拟chrome浏览器搜索关键字,返回第一页url
#!/usr/bin/python
#coding:utf-8
import urllib,urllib2,cookielib,re,sys,os,time,random
cj = cookielib.CookieJar()
str1 = 'Apple-Mon identifiant Apple' #0
str2 = 'Woolworths - Customer Satisfaction Survey'#0
@Harryyan
Harryyan / Snapshot
Created April 22, 2014 03:17
使用phantomjs实现网页批量截图,网页url可存在txt文件中
// Render Multiple URLs to image
var RenderUrlsToImage, arrayOfUrls, system;
system = require("system");
var fs = require('fs');
/*
Render given urls
@param array of URLs to render
@Harryyan
Harryyan / Sort Algorithms
Created April 13, 2014 08:35
利用python实现4中插入类排序算法,希尔排序,直接插入排序,二路插入排序,折半插入排序
#!/usr/bin/python
class SortAlgorithms:
#direct insertion sort
def insertion_sort(self,data):
for index in range(1,len(data)):
for inner_index in range(0,index):
if data[inner_index] >= data[index]:
data.insert(inner_index,data[index])
del(data[index+1])
@Harryyan
Harryyan / shell sort
Created April 8, 2014 01:41
Ruby实现希尔排序
#!/usr/bin/env ruby
def shell_sort data,increment
len_data = data.length
len_increment = increment.length
for k in 0..(len_increment - 1)
for i in increment[k]..(len_data - 1)
tmp = data[i]
j = i
@Harryyan
Harryyan / two-way binary sort
Created April 6, 2014 03:54
Ruby实现2路插入排序;2路插入排序基于折半插入排序
#!/usr/bin/env ruby
def two_way_sort data
first,final = 0,0
temp = []
temp[0] = data[0]
result = []
len = data.length
for i in 1..(len-1)
@Harryyan
Harryyan / insertion Sort
Created March 31, 2014 13:12
ruby实现的两种代码量较少的直接插入排序算法,一种是需要另一个数组,一种是不需要额外数组的
#This way is the easy way to do insertion sort, but needs create a new array
class InsertionSort
def sort_out_of_place(to_sort)
sorted = []
to_sort.each do |element|
for index in 0..(to_sort.length - 1)
sorted.insert(index, element) if to_sort[index] > element
end
end