Skip to content

Instantly share code, notes, and snippets.

@zeroDivisible
zeroDivisible / Problem #31
Created January 20, 2013 22:05
This is simple solution to Problem #31 on Project Euler.
public class problem31 {
final static int TOTAL = 200;
public static void main(String[] args) {
int[] coins = {1, 2, 5, 10, 20, 50, 100, 200};
int[] ways = new int[TOTAL + 1];
ways[0] = 1;
for(int coin: coins)
for(int j = coin; j <= TOTAL; j++)
@zeroDivisible
zeroDivisible / gist:5495400
Created May 1, 2013 13:56
Postgres transactions.
src/backend/access/transam/README
The Transaction System
======================
PostgreSQL's transaction system is a three-layer system. The bottom layer
implements low-level transactions and subtransactions, on top of which rests
the mainloop's control code, which in turn implements user-visible
transactions and savepoints.
@zeroDivisible
zeroDivisible / build.gradle
Created June 12, 2013 20:33
Excuding dependnecy module-wide in Gradle.
// YOU SHALL NOT PASS!
configurations {
all*.exclude module: 'commons-logging'
}
@zeroDivisible
zeroDivisible / gist:5777707
Created June 13, 2013 21:53
install latest jsvc in Chef using provided rpm package.
# install latest version of jsvc package from yum
rpm_package "jakarta-commons-daemon-jsvc-1.0.1-8.9.el6.x86_64.rpm" do
action :install
source "/tmp/#{JSVC}"
options "--nodeps"
end
@zeroDivisible
zeroDivisible / gist:5805565
Created June 18, 2013 13:57
Java encoding and String.getBytes() issues. Taken from http://stackoverflow.com/a/12659462/126781
It is a bit complicated ...
Java tries to use the default character encoding to return bytes using String.getBytes().
The default charset is provided by the system file.encoding property.
This is cached and there is no use in changing it via the System.setProperty(..) after the JVM starts.
If the file.encoding property does not map to a known charset, then the UTF-8 is specified.
.... Here is the tricky part (which is probably never going to come into play) ....
If the system cannot decode or encode strings using the default charset (UTF-8 or another one), then there will be a fallback to ISO-8859-1. If the fallback does not work ... the system will fail!
@zeroDivisible
zeroDivisible / gist:5827190
Created June 20, 2013 22:12
General bash script.
#!/bin/bash
case $1 in
tags)
# extract tags
cat $2 | cut -d '|' -f 8 | sed "y/;/\n/;" | sed -e '/
/d' | sort | uniq > tags
;;
movies)
# extract movie details
@zeroDivisible
zeroDivisible / Postgres Check Database Size.
Created June 21, 2013 21:43
Check database size of current database in PostgreSQL.
SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
ELSE 'No Access'
END AS Size
FROM pg_catalog.pg_database d
ORDER BY
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_database_size(d.datname)
ELSE NULL
/* Flatten das boostrap */
.well, .navbar-inner, .popover, .btn, .tooltip, input, select, textarea, pre, .progress, .modal, .add-on, .alert, .table-bordered, .nav>.active>a, .dropdown-menu, .tooltip-inner, .badge, .label, .img-polaroid {
-moz-box-shadow: none !important;
-webkit-box-shadow: none !important;
box-shadow: none !important;
-webkit-border-radius: 0px !important;
-moz-border-radius: 0px !important;
border-radius: 0px !important;
border-collapse: collapse !important;
background-image: none !important;
@zeroDivisible
zeroDivisible / gist:5850752
Last active December 18, 2015 21:58
invalidate the session in servlet and redirect the user to he same url, making normal processes to kick in.
// invalidate the session
session.invalidate();
// redirect the user to where they were, so normal login process can kick in
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpServletRequest request = (HttpServletRequest) servletRequest;
StringBuffer requestUrl = request.getRequestURL();
// by default all GET params from query string will be missing from getRequestURL, let's reconstruct it
if (request.getQueryString() != null) {
DS.RESTAdapter.registerTransform('raw', {
deserialize: function(serialized) {
return serialized;
},
serialize: function(deserialized) {
return deserialized;
}
});
App.Movie = DS.Model.extend({