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
/* | |
== Adapted from the code over at https://gist.github.com/graymouser/a33fbb75f94f08af7e36 == | |
Log into your account at packtpub.com and save the cookies with the "cookies.txt" Chrome extension or the "Export cookies" Firefox extension into the file cookies.txt. | |
Then open the console in your browsers dev tools and paste the following code. | |
You will get a list of wget commands that you can copy and paste as a whole into a terminal to download all books. | |
Example: wget --load-cookies=cookies.txt --content-disposition "https://packtpub.com//ebook_download/20217/mobi" -O "R Data Visualization Cookbook.mobi" | |
If you only want some filetypes, edit the "pattern" vaiable accordingly. |
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 datetime | |
FORMAT = '%d/%m/%Y' | |
def next_weekday(d, weekday): | |
days_ahead = weekday - d.weekday() | |
if days_ahead <= 0: # Target day already happened this week | |
days_ahead += 7 | |
return d + datetime.timedelta(days_ahead) |
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
package main | |
import "fmt" | |
func fibonacci() func() int { | |
a, b := 0, 1 | |
return func() int { | |
b, a = a + b, b | |
return a | |
} |
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 collections import OrderedDict | |
N = 2000 | |
WORDS = ["pool", "loco", "cool", "stain", "satin", "loop"] * N + ["pretty", "nice"] | |
def get_anagrams_default_orddict(words=WORDS): | |
normalized = [''.join(sorted(w)) for w in words] | |
d = OrderedDict() | |
for i, n in enumerate(normalized): |
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 math | |
def get_e(): | |
from decimal import Decimal, getcontext | |
getcontext().prec = 200 # improve precision | |
e, f, n = Decimal(0), Decimal(1), Decimal(1) | |
while True: | |
old_e = e | |
e += Decimal(1) / f |
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 python | |
import argparse | |
def remove_duplicated(ss, verbose=False): | |
if verbose: print "initial " + ss | |
s = [x for x in ss] | |
duplicated = 0 | |
for i in range(1, len(s)): | |
if s[i] == s[i-1]: duplicated += 1 | |
s[i-duplicated] = s[i] |