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
import pdfkit | |
# Fill this list with the html pages you want to be converted | |
file_list = [] | |
# Disable links since some point to local hard drive and dont work | |
pdfkit.from_file(file_list, "generatedpdf.pdf", options={"disable-external-links": None, "load-error-handling": "ignore"}) |
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
def selection_sort(nums): | |
nums_length = len(nums) | |
if nums_length < 2: | |
return nums | |
for k in range(nums_length): | |
for i in range(k, nums_length): | |
if i == k: | |
smallest_idx, smallest = i, nums[i] | |
else: |
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
def insertion_sort(nums): | |
nums_length = len(nums) | |
if nums_length < 2: | |
return nums | |
for i in range(1, nums_length): | |
x = i-1 | |
while nums[i] < nums[x] and x >= 0: | |
x -= 1 | |
else: | |
nums.insert(x+1, nums[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
from typing import List | |
def quicksort(ints: List[int]): | |
if len(ints) < 2 or len(set(ints)) == 1: | |
return ints | |
pivot = ints[0] | |
ints_less_than_pivot = [x for x in ints[1:] if x <= pivot] | |
ints_more_than_pivot = [x for x in ints[1:] if x > pivot] | |
return quicksort(ints_less_than_pivot) + [pivot] + quicksort(ints_more_than_pivot) |
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
object FirstClassFunctions { | |
def sum(f: Int => Int)(a: Int, b:Int): Int = { | |
def iter(a: Int, result: Int): Int = | |
if (a > b) result | |
else iter(a + 1, f(a) + result) | |
iter(a,0) | |
} | |
def main(args: Array[String]) { | |
println("Sum is: " + sum(x => x)(1,10)) |
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
import unittest | |
def flatten(arg_list, result_list): | |
""" Flatten an array of arbitrarily nested arrays of | |
integers into a flat array of integers. """ | |
for x in arg_list: | |
if isinstance(x, list): | |
flatten(x, result_list) | |
else: |
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
from itertools import groupby | |
from operator import itemgetter | |
myvals = [('hello', 'arrival'), ('hi', 'arrival'), ('test', 'no'), ('voo', 'yes'), ('cool', 'arrival')] | |
[(a,map(itemgetter(1), b)) | |
for a,b in groupby( # 4. Group by key for which you have create list. | |
sorted([(x, # 3. Sort the keys like arrival, yes, etc. | |
reduce(lambda a,b: a+' '+b, map(itemgetter(0), y))) # 2. Concantenate the strs with same contiguous key. | |
for x,y in groupby(myvals, key=lambda e: e[1])]), # 1. Group by key for which you have to concat str. |
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
def mergesort(arr, n): | |
if n == 1: return arr | |
len_half = int(n/2) | |
return merge(mergesort(arr[:len_half], len_half), | |
mergesort(arr[len_half:], n - len_half), n) | |
def merge(arr1, arr2, n): | |
result = [] | |
i,j = 0,0 | |
for x in range(n): |
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
import rlcompleter, readline | |
readline.parse_and_bind('tab: complete') |
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
object CompoundOrGate { | |
type Action = () => Unit | |
class Wire { | |
private var sigVal = false | |
private var actions: List[Action] = List() | |
def getSignal = sigVal | |
def setSignal(s: Boolean) = | |
if (s != sigVal) { | |
sigVal = s |
NewerOlder