Skip to content

Instantly share code, notes, and snippets.

View c0deful's full-sized avatar
🐢

Dominik Plewa c0deful

🐢
  • Software Engineer
  • Warsaw, Poland
  • LinkedIn in/dplewa
View GitHub Profile
@c0deful
c0deful / whu-spider.py
Created January 19, 2018 13:36
Warhammer Underworlds Library card image scrapper
import json, urllib.request, urllib.parse
# API url can be found in WHU Library JS source:
# https://warhammerunderworlds.com/wp-content/themes/gw-shadespire/library/js/main.js?ver=5.3
CARDS_JSON_URL = 'https://warhammerunderworlds.com/wp-json/wp/v2/cards/?per_page=300&lang=ENG'
opener = urllib.request.build_opener()
# urllib is banned on the server, so provide an innocent user agent
opener.addheaders = [('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11')]
@lpar
lpar / utf8truncate.java
Created June 17, 2011 18:21
Truncate a Java string so that its UTF-8 representation will not exceed the specified number of bytes
/**
* Truncate a Java string so that its UTF-8 representation will not
* exceed the specified number of bytes.
*
* For discussion of why you might want to do this, see
* http://lpar.ath0.com/2011/06/07/unicode-alchemy-with-db2/
*/
public static String utf8truncate(String input, int length) {
StringBuffer result = new StringBuffer(length);
int resultlen = 0;