Skip to content

Instantly share code, notes, and snippets.

@tuxskar
tuxskar / packtpub_get_your_library_books.js
Last active July 23, 2019 15:06 — forked from juzim/packtpub_get_dl_links.js
Create wget commands for all claimed books on packtpub
/*
== 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.
@tuxskar
tuxskar / Get calendar dates.py
Created September 14, 2016 07:27
Passing as arguments the first day (first_date), the number of weeks between events (k), the days of the week (days_of_the_week) and the number of next event requested (n) will answer with the n next appointment dates
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)
@tuxskar
tuxskar / Fibonacci in Go
Created October 27, 2015 20:35
One of my first programs in Go, the Fibonacci
package main
import "fmt"
func fibonacci() func() int {
a, b := 0, 1
return func() int {
b, a = a + b, b
return a
}
@tuxskar
tuxskar / Finding anagrams
Last active August 29, 2015 14:19
Anagram finder
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):
@tuxskar
tuxskar / first 10-digit prime found in consecutive digits of e
Created April 3, 2015 20:02
Puzzle "first 10-digit prime found in consecutive digits of e"
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
@tuxskar
tuxskar / Remove duplicate chars on strings script
Last active August 29, 2015 14:12
Script to remove duplicate chars in strings with O(n) complexity for each string
#!/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]