Skip to content

Instantly share code, notes, and snippets.

@nking
nking / gist:ba445eda58307d3dd96a
Last active August 29, 2015 14:20
TopCoder FlowerGarden dynamic programming exercise
/**
* implementing a dynamic programming solution as an exercise for
* https://www.topcoder.com/community/data-science/data-science-tutorials/dynamic-programming-from-novice-to-advanced/
*
* The runtime complexity is O(N^2).
*
Note, that their Test 4 shows that the end result is consistent with rules
only for adjacent rows.
result indexes= 1 3 5 0 2 4 from original order
height 2 4 6 1 3 5
UML Class Diagrams can be made with graphviz.
(1) download graphviz
http://www.graphviz.org/Download.php
(2) write your dot file.
Note that in your dot file, you may want to exclude most dependencies
because the dot layout algorithm will weigh them equally with
the inheritance edges and you probably want a preference for better
display of the inheritance and composition relationships.
Generating Coverage Reports with Xcode 5.1.1
If you need to test using the IOS 6.x simulator due to
testing in-app purchases, for example, you won't be able to use
the new XCTest library as those are IOS >= 7. The apple store
(simulator) is only available in the IOS 6.x simulators.
The notes below use GTM UnitTesting which are extensions
of SenTestingKit instead of XCTest.
This is an example of targets built for an older Xcode project that
@nking
nking / gist:2727904
Created May 18, 2012 22:28
javadoc Annotation processing exceptions
If you're seeing
java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast
to com.sun.javadoc.AnnotationTypeDoc
the classloader used by the javadoc tool is not finding your 3rd party
annotation definitions.
This is a problem present in JDK 1.6.
An quick workaround to enable the classloader to find the annotation definitions
@nking
nking / gist:1327349
Created October 31, 2011 12:06
CSS bubbles
Can make a bubble with a CSS3 opacity gradient placed over any background.
<div class='abubble'>
<div class='innerbubble'></div>
</div>
and change the location of the bubble and it's size by changing the properties in the .bubble class selector.
.abubble {
@nking
nking / appenginecustomtransforms
Created September 1, 2011 03:47
appengine custom transforms
Notes on exporting and importing data to appengine.
Schema refactoring or complex relationships between entities may
require custom transforms to be written and added to the config yaml
file that the bulkloader generates automatically.
A few helpful resources on that are
http://wereword-gae.googlecode.com/hg/backup/helpers.py
http://bulkloadersample.appspot.com/
http://longsystemit.com/javablog/?p=23
@nking
nking / gist:1185346
Created September 1, 2011 03:13
Android sqlite database schema version tests
If you want to test upgrades of your database schemas against new releases that have
included database version changes:
To save your database,
adb shell pull /data/data/your.android.package.name/databases/yourprojectname.db \
/yourprojectcvsdir/databases/yourprojectname_version.db
If you're using a ContentProvider such as given by the Android example
http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html
make the methods accepting SQLiteDatabase arguments accessible. In the example
@nking
nking / gist:1141609
Created August 12, 2011 07:02
Two operation updates in Google's Appengine using two, 2-phase locking transactions
The goal is to insert a new event and update the counter for it and have both
operations fail or both succeed. The solution below places each of these
2 operations is in a 2 two-phase locking transaction which must attempt to
both succeed or fail, and so the pattern of
lock1 operation1 (commit1 and lock2 operation2 commit2) or (rollback1)
is applied, with an additional pattern of first operation successfully committed
with the second retried if it fails.
private Key insert(Event event) {
@nking
nking / sharded counters in Google's Appengine
Created March 12, 2011 04:44
memcache implementation of sharded counters with Google's Appengine
The sharded counter approach to keeping track of the number of entities of a
given type is in Appengine article:
http://code.google.com/appengine/articles/sharding_counters.html
Google's Appengine cloud services are optimized for reads, so for high frequency
updates and to keep track of entities when there are more than 1000 (=count limit),
a sharded counter approach using the datastore and memcache is used below.
The sharded counter approach is to divide the container holding the sum of values
into multiple containers that are randomly chosen and less likely to be accessed
Here's a way to make an activity indicator that is simple to import into an
activity, and allows the rest of the window to continue receiving events.
The 5 classes ActivityIndicatorView.java, ActivityIndicatorListener.java,
IActivityIndicatorCallback.java, ActivityIndicatorAction.java, and ActivityIndicatorEventTypes.java are printed below 2 snippets showing how
to import the view and how to broadcast messages that the view will indirectly
respond to.
The animation is in ActivityIndicatorView.java which extends android.view.View.
It renders a simple activity indicator and registers itself as a callback for