Skip to content

Instantly share code, notes, and snippets.

View software-mariodiana's full-sized avatar

Mario Diana software-mariodiana

View GitHub Profile
@software-mariodiana
software-mariodiana / BottleRocket.py
Created June 4, 2014 18:21
A hello world example for using Bottle with Rocket.
from rocket import Rocket
from bottle import Bottle
from bottle import route
app = Bottle(__name__)
app.debug = True
@software-mariodiana
software-mariodiana / 0_reuse_code.js
Created June 5, 2014 16:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@software-mariodiana
software-mariodiana / AsyncPlistLoad.m
Last active August 29, 2015 14:02
Instantiating an array by loading a plist file asynchronously, and using a block to notify the associated UITableView to reload its data.
/*
* Assume the following:
*
* - The Plist file is called: Names.plist
* - @property NSArray *tableData
* - Callback block messages UITableView with reloadData
*/
- (void)initizeDataWithTableViewCallback:(void(^)(void))reloadDataMessage
{
@software-mariodiana
software-mariodiana / UsingUILocalizedIndexCollation.m
Created June 7, 2014 19:08
How to use a UILocalizedIndexCollation to create a table with sections.
/*
* Assume the following:
*
* @property UILocalizedIndexCollation *collation;
* @property NSMutableArray *sections;
* @property NSArray *tableData;
*/
- (void)configureSectionData
{
@software-mariodiana
software-mariodiana / DbRecordsToNamedTuple.py
Last active August 29, 2015 14:02
How to take the tuples returned from a database query and convert them into named tuples.
from collections import namedtuple
# Assume a previously executed query.
rows = cursor.fetchall()
# Index 0 of the metadata returned is the column name.
columns = [aColumn[0] for aColumn in cursor.description]
NamedRow = namedtuple('NamedRow', columns)
# A generator may help with larger datasets.
@software-mariodiana
software-mariodiana / SafeStack.py
Created June 24, 2014 13:39
A short example of how to build a Jython class subclassed from a Java class.
# http://www.jython.org/archive/21/docs/subclassing.html
import java.lang
import java.util
class SafeStack(java.util.Stack):
"""
http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html
@software-mariodiana
software-mariodiana / mycsv.py
Last active August 29, 2015 14:03
I found a CSV file created by Crystal Reports that had double-quoted fields, some of which contained commas between the quotes. We don't want to split at those commas, so the regular string.split(',') command wouldn't work. The code goes through the string twice: once to find the splice values for the various fields, and then a second time to do…
def splitStringWithBadlyFormedCSV(aString):
"""
Return list of fields in aString, splitting by commas while ignoring
commas that appear within double-quoted strings.
"""
ignore = False
splices = list()
anchor = 0
for cursor in range(len(aString)):
character = aString[cursor]
@software-mariodiana
software-mariodiana / pom.xml
Last active August 29, 2015 14:03
A sample, maven build file for a RESTEasy web app, that includes downloading dependencies.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mariodiana.rest</groupId>
<artifactId>RESTfulExample</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>RESTfulExample Maven Webapp</name>
@software-mariodiana
software-mariodiana / MySampleRESTApplication.java
Last active August 29, 2015 14:03
Paired together with pom.xml gist, this demos automagical loading of REST resources in a standalone servlet container (e.g., Tomcat).
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import javax.servlet.ServletContext;
import org.slf4j.Logger;
@software-mariodiana
software-mariodiana / web.xml
Created July 11, 2014 14:14
Bare bones web.xml file, suitable for RESTEasy application.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>