Skip to content

Instantly share code, notes, and snippets.

@jdmullin
jdmullin / resty read timeout
Created March 12, 2014 22:56
Resty with URLConnection read timeout
public class ReadTimeoutOption extends Resty.Option {
private final int _readTimeout;
public ReadTimeoutOption(int milliseconds) {
_readTimeout = milliseconds;
}
public void apply(URLConnection aConnection) {
aConnection.setReadTimeout(_readTimeout);
}
@jdmullin
jdmullin / category hierarchy proc
Created March 5, 2014 22:18
Stored procedure to return hierarchical data
drop procedure if exists category_hier;
delimiter #
create procedure category_hier
(
in p_cat_id smallint unsigned,
in p_name_separator varchar(3) -- string to separate full name path segments
)
begin
@jdmullin
jdmullin / oldIdempotentAlter.sql
Created July 15, 2013 17:11
Older pattern for idempotent alter scripts
SELECT count(*)
INTO @exist
FROM information_schema.columns
WHERE table_schema = 'databaseName'
and COLUMN_NAME = 'columnName'
AND table_name = 'tableName';
set @query = IF(@exist <= 0,
'alter table whatever',
'select \'Column already exists\' status');
@jdmullin
jdmullin / idempotentAlter.sql
Last active December 19, 2015 18:49
Pattern for idempotent sql alter scripts using temporary stored procedures to implement conditional logic.
delimiter //
drop procedure if exists trySomething//
create procedure trySomething(in _param1 int, in _param2 int)
begin
-- Condition could be a count, a boolean, whatever. In this case assuming might be running a "select count(*)"
-- to determine if a certain row has already been inserted.
declare _condition int default null;
set _condition = (<SOME_SELECT_THAT_SIGNIFIES_IF_YOUVE_ALREADY_RUN_THIS_SCRIPT>);