Skip to content

Instantly share code, notes, and snippets.

@friek
friek / JAXBUtils.java
Created November 3, 2015 21:27
JAXB marshalling and unmarshalling
import javax.xml.bind.JAXB;
import java.io.StringReader;
import java.io.StringWriter;
public class JAXBUtils
{
/**
* Unmarshal an XML string
* @param xml The XML string
* @param type The JAXB class type.
@friek
friek / remove_known_host.sh
Created October 29, 2015 09:44
Script to remove an entry from the ssh known hosts file
#!/bin/bash -e
line_num="$1"
if [ -z "$line_num" ]; then
echo "Usage: $0 <line num>"
exit 1
fi
known_hosts="${HOME}/.ssh/known_hosts"
tmp_file="${known_hosts}.$$"
@friek
friek / prefix_stdx.sh
Created July 9, 2015 08:48
bash prefix stdout/stderr of command output
#!/bin/bash
# Case 1: prefix stdout with 'test'
exec 1> >(sed 's/^/test /')
# Case 2: prefix a group of commands with 'test'
{
echo "prefixed line"
} > >(sed 's/^/test /')
@friek
friek / pywebserv.py
Created July 6, 2015 08:19
Python SimpleHTTPServer with address reusage
#!/usr/bin/env python
import SimpleHTTPServer
import SocketServer
import sys
import os
import getopt
def main(argv):
try:
@friek
friek / FileReader.java
Created July 1, 2015 09:12
One liner for reading a file in Java.
package file;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
public class FileReader
{
public static void main(String[] args) throws IOException
@friek
friek / .editrc
Created May 26, 2015 15:31
MySQL client .editrc for backwards compatibility with libreadline
# Ctrl+W to delete the previous word
bind "^W" ed-delete-prev-word
# Ctrl+U to delete the current line contents
bind "^U" vi-kill-line-prev
# Ctrl+R to search the query history
bind "^R" em-inc-search-prev
# Ctrl+Left Arrow to go the previous word
bind "\e[1;5D" vi-prev-word
# Ctrl+Right Arrow to go to the next word
bind "\e[1;5C" vi-next-word
@friek
friek / CURRENT_TIME_MILLIS.sql
Created January 27, 2015 12:44
MySQL to return the current timestamp + milliseconds
CREATE FUNCTION CURRENT_TIME_MILLIS ()
RETURNS BIGINT
LANGUAGE SQL
SQL SECURITY INVOKER
BEGIN
DECLARE _time BIGINT;
select conv(concat(substring(uid,16,3), substring(uid,10,4), substring(uid,1,8)), 16,10)
div 10000 - (141427 * 24 * 60 * 60 * 1000) into _time
from (select uuid() uid) as alias;
@friek
friek / Resource.java
Created January 15, 2015 20:23
Minimal jaxrs setup
import javax.persistence.*;
@Entity
public class Resource
{
@Id
private int id;
private String value;
public int getId()
@friek
friek / designer.html
Last active August 29, 2015 14:11
designer
<link rel="import" href="../core-pages/core-pages.html">
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@friek
friek / designer.html
Last active August 29, 2015 14:11
designer
<link rel="import" href="../core-field/core-field.html">
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../core-input/core-input.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">