Skip to content

Instantly share code, notes, and snippets.

View ae6rt's full-sized avatar

Mark Petrovich ae6rt

  • Petaluma, CA
View GitHub Profile
@ae6rt
ae6rt / kotlin-tuples
Created March 5, 2012 02:33
Kotlin tuples
fun getRuntimeParams(args: Array<String>) : #(String?, String?) {
var t = 0
var targetListName : String? = null
var since : String? = null
while(t < args.size) {
if( args[t].equals("--list")) {
targetListName = args[++t]
}
if( args[t].equals("--since")) {
@ae6rt
ae6rt / extfun.kt
Created March 12, 2012 00:07
Kotlin extension functions
package extfun
import java.util.List
import java.util.ArrayList
fun main(args : Array<String>) : Unit {
swapEm()
/*
Output is
[3, 2, 1]
@ae6rt
ae6rt / each.kt
Created March 12, 2012 03:40
Kotlin .each extension method on Collection<T>
package litfunc
import java.util.ArrayList
import java.util.Collection
fun main(args : Array<String>) : Unit {
val l = ArrayList<String>()
l.add("one")
l.add("two")
l.add("buckle my shoe")
@ae6rt
ae6rt / sql.awk
Created August 31, 2012 14:00
Analyzing SQL with awk
Use awk's multiline pattern matching to select, for example, create-table statements in a database schema:
$ mysqldump --no-data -u theuser -p mysql | awk '/CREATE TABLE/,/;/'
CREATE TABLE `columns_priv` (
`Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
`Db` char(64) COLLATE utf8_bin NOT NULL DEFAULT '',
`User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',
`Table_name` char(64) COLLATE utf8_bin NOT NULL DEFAULT '',
`Column_name` char(64) COLLATE utf8_bin NOT NULL DEFAULT '',
`Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
@ae6rt
ae6rt / gist:3697746
Created September 11, 2012 11:35
The four ways to deploy a webapp to Tomcat
There are four different ways one can deploy a webapp to Tomcat. If TCHOME is the Tomcat top-level directory:
* Copy the war file foo.war or exploded war directory to TCHOME/webapps
* Create a context file context.xml in the webapp’s META-INF/ directory that contains a <Context> fragment that describes the webapp deployment
* Add a <Context> element to the <Host> element in Tomcat’s server.xml that describes the webapp deployment, including docBase. docBase is a <Context> attribute that locates the war file or exploded war directory in the filesystem.
* Create a context file foo.xml in TCHOME/conf/Catalina/localhost/foo.xml that contains a <Context> fragment that describes the webapp deployment, including docBase.
The first two methods do not provide the freedom to name the servlet context independent of file system names for the war file or exploded war directory, whereas the last two do. Of the two methods that provide control over context naming, the most appealing is the use of a context file foo.xml p
@ae6rt
ae6rt / gist:3805639
Created September 30, 2012 02:07
TestNG counter of DataProvider rows
@Override
public void onTestStart(ITestResult iTestResult) {
// Attempt to count invocations of a DataProvider-instrumented test
Object instance = iTestResult.getInstance();
ITestNGMethod testNGMethod = iTestResult.getMethod();
Method testMethod = testNGMethod.getMethod();
if (testMethod.isAnnotationPresent(Test.class) && testMethod.isAnnotationPresent(Count.class)) {
Test testMethodTestAnnotation = testMethod.getAnnotation(Test.class);
String dataProviderName = testMethodTestAnnotation.dataProvider();
if (dataProviderName != null && !dataProviderName.isEmpty()) {
@ae6rt
ae6rt / gist:5069569
Created March 2, 2013 03:28
Angular tail function
$scope.tail = function (tailbag) {
if (tailbag.processid.length === 0) {
console.log("Cannot tail " + tailbag.whoami + " because there is no processid");
return;
}
$http.get("tail", {params: {"processid": tailbag.processid, "start": tailbag.currentStart, "limit": tailbag.pageSize}})
.success(function (data, status, headers, config) {
tailbag.currentStart = tailbag.currentStart + data.page.length;
for (k = 0; k < data.page.length; ++k) {
tailbag.text = tailbag.text + data.page[k] + "\n";
@ae6rt
ae6rt / MarkP keymap
Last active December 19, 2015 04:29
IntelliJ keymap, with git revert and tab-close shortcuts
<?xml version="1.0" encoding="UTF-8"?>
<keymap version="1" name="MarkP" parent="Mac OS X">
<action id="CloseAllEditorsButActive">
<keyboard-shortcut first-keystroke="meta alt X" />
</action>
<action id="CloseContent">
<keyboard-shortcut first-keystroke="meta F4" />
<keyboard-shortcut first-keystroke="meta alt W" />
</action>
<action id="EditorCodeBlockEndWithSelection" />
@ae6rt
ae6rt / gist:5902241
Created July 1, 2013 16:12
DOT specification enroute to becoming at PTL program
digraph G {
rankdir=LR;
main [shape=box];
main -> f -> g; // main calls f which calls g
f -> f [style=dotted] ; // f is recursive
f -> h; // f calls h
}
@ae6rt
ae6rt / gist:6046413
Last active December 20, 2015 01:08
Restrict access on an S3 bucket to a set of operations
{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:ListBucket",
"s3:GetBucketAcl",
"s3:PutBucketAcl"
],