Skip to content

Instantly share code, notes, and snippets.

@shyiko
shyiko / SequenceFileAppender.java
Created December 4, 2011 10:57
Hadoop SequenceFileAppender
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Writable;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
@shyiko
shyiko / AdvisoryLocking.sql
Created December 27, 2011 13:12
PostgreSQL Advisory Locking
<tableid> = select oid from pg_class where relname = '<tablename>';
<rowid> = select id from (
select rr.id from <tablename> rr left join pg_locks pgl
on pgl.classid = <tableid> and pgl.objid = rr.id
where pgl.objid is null limit 1
) iq where pg_try_advisory_lock(<tableid>, id);
-- select * from pg_locks where locktype = 'advisory';
select pg_advisory_unlock(<tableid>, <rowid>);
@shyiko
shyiko / Cache.java
Created January 4, 2012 17:52
SoftReferenceMap
public class Cache<K, V> {
private final Map<K, SoftReference<V>> map;
public Cache(final int cacheSize) {
map = Collections.synchronizedMap(new LinkedHashMap<K, SoftReference<V>>() {
@Override
protected boolean removeEldestEntry(java.util.Map.Entry<K, SoftReference<V>> eldest) {
return size() > cacheSize;
@shyiko
shyiko / mvnfy
Created February 12, 2012 21:55
Maven powered with Ubuntu Notify OSD
#!/bin/bash
mvn $*
if [ $? -gt 0 ]
then
notify-send -i /usr/share/icons/Humanity/status/64/dialog-warning.svg "Maven" "Build failed."
else
notify-send -i /usr/share/icons/Humanity/actions/64/gtk-info.svg "Maven" "Build succeeded."
fi
@shyiko
shyiko / InvocationLocal.java
Created May 17, 2012 20:19
InvocationLocal<T>
/**
* Provides method-invocation-scope variables.
* <p/>
* Each invocation of {@link #get()} within same method (including nested calls) will yield value previously set by
* {@link #set(Object)}. Once {@link #set(Object)} region ends, value is rolled back to the default one (provided
* during {@link InvocationLocal} instance construction).
* <p/>
* Implementation is thread-safe.
*
* @author <a href="mailto:sshyiko@cogniance.com">sshyiko</a>
@shyiko
shyiko / shell.script.template.in.coffee
Created July 22, 2013 20:29
Template of shell script in CoffeScript
#!/usr/bin/env coffee
###
prerequisites;
$ sudo apt-get install nodejs # whatever
$ sudo npm install -g coffee-script
###
bootstrap = do ->
exec = require('child_process').exec
@shyiko
shyiko / pom.xml
Created July 27, 2013 19:33
shyiko/servers-maven-extension inquiry (#1)
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>land.of.ooo</groupId>
<artifactId>adventure_time</artifactId>
<version>0.1.0-SNAPSHOT</version>
@shyiko
shyiko / 6746525-gradle-based-project.zip
Last active December 24, 2015 04:49
(WebStorm 7.0) TODO highlighting fix for CoffeeScript plugin
@shyiko
shyiko / keybase.md
Created October 11, 2016 00:19
keybase.md

Keybase proof

I hereby claim:

  • I am shyiko on github.
  • I am shyiko (https://keybase.io/shyiko) on keybase.
  • I have a public key whose fingerprint is 0E9D 330A 7704 EFB3 4BB3 6842 E6A6 4EED 7505 2A29

To claim this, I am signing this object:

@shyiko
shyiko / google_font_downloader
Created October 22, 2016 07:54 — forked from jakeg/google_font_downloader
Download all Google fonts using sensible FVD-style names
/*
Script to download all google fonts and name them with FVD-based filenames
- e.g. Rock_Salt.n4.ttf, Open_Sans.i7.ttf
*/
var https = require('https');
var http = require('http');
var fs = require('fs');
var async = require('async');
var key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // google fonts api server-only key