Skip to content

Instantly share code, notes, and snippets.

@guoguo12
guoguo12 / TextRenderer.java
Last active August 29, 2017 15:44
This is one way to display subscript and superscript text using Libgdx. The markup used assumes that, in the raw string, subscript text is surrounded by underscores and superscript text is surrounded by carets. "bigFontName" and "smallFontName" correspond to fonts in the skin argument. See this blog post for more details: http://www.sparkfiregam…
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
@guoguo12
guoguo12 / CoordinateUtils.java
Last active February 22, 2016 02:20
Released source code files from Lines 1.0, a puzzle game created by Sparkfire Games. Get the binary at https://github.com/guoguo12/guoguo12.github.io/tree/master/projects/lines.
package sparkfire.lines.game;
import sparkfire.lines.actors.GameNode;
import sparkfire.lines.actors.GameWall;
import com.badlogic.gdx.Gdx;
/**
* Contains conversion functions for locations of in-game objects, such as
* {@link GameNode} and {@link GameWall} objects.
@guoguo12
guoguo12 / commonscat.diff
Created November 19, 2013 11:34
Diff for bug report for valhallasw/gerrit-patch-uploader.
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
new file mode 100755
index 0000000..064ba72
--- /dev/null
+++ b/scripts/commonscat.py
@@ -0,0 +1,631 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+With this tool you can add the template {{commonscat}} to categories.
@guoguo12
guoguo12 / remove_sources_tests.py
Created November 22, 2013 03:46
Tests for new method added to Wikimedia's pywikibot/core.
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Simple, crude tests for Claim's removeSources() method.
Tests are run on Wikidata's sandbox.
Allen Guo <Guoguo12@gmail.com>
November 2013
"""
@guoguo12
guoguo12 / claimit_exists_tests.txt
Last active December 29, 2015 09:39
Input/output from a series of command-line tests for the "exists" option for the claimit.py script in Wikimedia's pywikibot/core. See this bug report for more information: https://bugzilla.wikimedia.org/show_bug.cgi?id=54415.
# The test item used is Wikidata's sandbox item, Q4115189.
$ python pwb.py claimit -page:"Wikipedia:Wikidata/Wikidata Sandbox" P246 "Test string"
Processing [[en:Wikipedia:Wikidata/Wikidata Sandbox]]
Skipping P246 because claim with same property already exists
Use the -exists:p option to override this behavior
$ python pwb.py claimit -page:"Wikipedia:Wikidata/Wikidata Sandbox" P246 "Test string" -exists:p
'exists' argument set to 'p'
Processing [[en:Wikipedia:Wikidata/Wikidata Sandbox]]
@guoguo12
guoguo12 / list_equals_tests.py
Created November 27, 2013 22:27
Code and tests for a list comparison function that ignores order and works for lists of unhashable items (like dictionaries). All tests behave as expected, but there might be cases where listsEqual() does not work as expected.
def listsEqual(list1, list2):
"""
Returns true if the lists are probably equal, ignoring order.
Works for lists of unhashable items (like dictionaries).
"""
if len(list1) != len(list2):
return False
if sorted(list1) != sorted(list2):
return False
for item in list1:
@guoguo12
guoguo12 / setnotificationtimestamp_test.py
Last active January 1, 2016 10:09
Test for the action=setnotificationtimestamp MediaWiki module. Implements the examples from the API documentation page (https://www.mediawiki.org/wiki/API:SetNotificationTimestamp).
#!/usr/bin/env python
import requests
from bs4 import BeautifulSoup
import urllib
USERNAME = 'username'
PASSWORD = 'password'
example_payload_1 = {'action': 'setnotificationtimestamp', 'format': 'xml', 'entirewatchlist': ''}
skipped ""
clarified "range of numbers" -> "string"
clarified "item / string" -> "item"
skipped "unsure- to be disscussed. (probably boolean or instance of type)"
clarified "string (actually integer: number of meters)" -> "number"
clarified "monolingual text (or item?)" -> "monolingual text"
clarified "item (quantity)" -> "number"
skipped "iri"
clarified "geo-coordinate" -> "coordinate"
clarified "value" -> "string"
@guoguo12
guoguo12 / property_proposals_stats.py
Last active January 1, 2016 19:59
Python script for gathering data type statistics for proposed Wikidata properties. Requires manual input to clarify non-standard data types. Prints final data in CSV format to stdout, along with a list of the clarifications used. Note: this script is now being hosted at https://github.com/JohnFLewis/Wikidata/. This page will no longer receive up…
#!/usr/bin/env python
"""
property_proposals_stats.py: Tabulates and exports statistics for proposed Wikidata properties.
Dependencies:
* Python (2.x)
* Requests (http://docs.python-requests.org/en/latest/)
Instructions:
@guoguo12
guoguo12 / edline_login.py
Created January 25, 2014 08:35
Demonstrates how to use Requests (http://docs.python-requests.org/en/latest/) to login to Edline (http://www.edline.net/).
import requests
HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36'}
LOGIN_URL = 'https://www.edline.net/InterstitialLogin.page'
LOGIN_POST_URL = 'https://www.edline.net/post/InterstitialLogin.page'
class Edline(object):