Skip to content

Instantly share code, notes, and snippets.

@happyrobots
happyrobots / pom.xml
Created December 11, 2010 06:42
Maven (2.2.1) Project pom.xml for JPA app with social network API libraries
<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>org.this</groupId>
<artifactId>project</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Project Name</name>
<url>http://example.com</url>
<description>My typical JPA app with social network API libraries.</description>
@happyrobots
happyrobots / rails-3-subdomains.md
Created December 19, 2010 18:46
Return values of request.subdomain

Return Values of request.subdomain

Cases

  • If request.url is 'http://d.a.b.c', request.subdomain returns 'd.a'
  • If request.url is 'http://a.b.c', request.subdomain returns 'a'
  • If request.url is 'http://b.c', request.subdomain returns empty string.
  • If request.url is 'http://c', request.subdomain returns empty string.

Whether port number is used does not affect return values.. of course.

@happyrobots
happyrobots / rubygems-path.sh
Created December 22, 2010 07:42
Exporting Ruby Gems' Executables in Linux
# This script might be useful for systems that don't use Ruby Version Manager.
# It has been tested on Ubuntu 10.04 and Fedora 14,
# and most probably it should work on other Linux distros as well.
# Assuming /opt/ruby-enterprise/bin folder contains all the gems' executables
# (e.g. bundle, rails, etc.),
# put the following line on the last line of /etc/profile
export PATH=/opt/ruby-enterprise/bin:$PATH
From the protocol reference:
% Names, in this protocol, are ASCII strings. They may contain letters (A-Z and
% a-z), numerals (0-9), hyphen ("-"), plus ("+"), slash ("/"), semicolon (";"),
% dot ("."), dollar-sign ("$"), and parentheses ("(" and ")"), but they may not
% begin with a hyphen. They are terminated by white space (either a
space char or
% end of line). Each name must be at least one character long.
I tried tube name "a-b+1/;.c.$()/()", and it worked for me :
http://groups.google.com/group/beanstalk-talk/browse_thread/thread/8b3db1ab9adcf5a4
@happyrobots
happyrobots / SomeBean.java
Created January 14, 2011 22:31
[Managed Bean] Making Primefaces 2.2.RC1 Data Table Filtering works with multiple selection mode.
// .. import statements
// ViewScoped is important for AJAX
@ManagedBean
@ViewScoped
public class SomeBean {
private T[] selectedElementsFromTheList;
private T[] copyOfSelectedElementsFromTheList;
private List<T> theList;
sudo useradd username -G gitosis,admin -d /home/username -s /bin/bash -m
cat /etc/passwd | grep username
# this should output the home directory for username
<html>
<head>
<title>Hello World! This is the title of the page :D</title>
<!-- Style makes your page look prettier. -->
<style>
body {background-color:#ccc}
#content {border:1px solid black}
.bigger {font-size:130%}
</style>
@happyrobots
happyrobots / CreatingWekaAttributes.java
Created February 13, 2011 20:14
Weka examples how to create attribute with different types.
FastVector validNominalValues = new FastVector(2);
validNominalValues.addElement("male");
validNominalValues.addElement("female");
Attribute nominalAttribute = new Attribute("gender", validNominalValues);
FastVector nullFastVector = null;
Attribute stringAttribute = new Attribute("userId", nullFastVector);
Attribute numericAttribute = new Attribute("humidity");
Instances dataSet = // ...
// Showing attribute-type pairs of dataSet
// Analogy with SQL: print field and field type of a table
Enumeration attributes = dataSet.enumerateAttributes();
while (attributes.hasMoreElements()) {
Attribute attribute = (Attribute) attributes.nextElement();
System.out.println(attribute.name() + ": " +
Attribute.typeToString(attribute.type()));
}
@happyrobots
happyrobots / CreatingWekaInstance.java
Created February 13, 2011 21:47
This is just one example of creating an instance in-memory. I think this way is readable and provides enough flexibility on attribute types (numeric, nominal, string).
Instances dataSet = // ...
Attribute stringAttribute = // ...
Attribute nominalAttribute = // ...
int numberOfAttributes = 3;
Instance instance = new SparseInstance(numberOfAttributes);
instance.setDataset(dataSet);
instance.setValue(numericAttribute, 8.8);