This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
NewerOlder