Skip to content

Instantly share code, notes, and snippets.

View agarciadom's full-sized avatar

Antonio García-Domínguez agarciadom

View GitHub Profile
@agarciadom
agarciadom / Tail.java
Created February 28, 2012 12:03
Implementation of "tail -n1" in Java, using RandomAccessFile and a byte[] buffer
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
/**
* Simple partial implementations of the <code>tail(1)</code> UNIX command.
*
@agarciadom
agarciadom / TestInstanceOf.java
Last active December 11, 2015 18:29
Small test program for checking the performance impact of an instanceof call (tl;dr: not much)
class A {}
class B extends A {}
class C {}
public class TestInstanceOf {
public static void main(String[] args) {
final B b = new B();
final C c = new C();
int i = 0, nA = 0;
@agarciadom
agarciadom / PCIMutationTest.java
Created March 21, 2013 19:48
Small experiment for finding out the definition of the PCI mutation operator. I don't really see how downcasting in Java will change the behaviour in most cases: non-static methods are resolved using the actual type instead of the declared type, after all.
class Parent {
@Override
public String toString() {
return "Parent";
}
}
class Child extends Parent {
@Override
public String toString() {
@agarciadom
agarciadom / dropdown.js
Last active August 5, 2020 08:45
LocalStorage-based dropdown menus with raw JavaScript. The shown/hidden menu state is preserved across loads. By default, everything is shown, and the page also degrades gracefully when JS is disabled. (Look 'ma, no JQuery!)
/*
Simple example of a dropdown menu using HTML5 LocalStorage.
*/
function create_dropdown(menu_id, category_title_class) {
var menu = document.getElementById(menu_id)
var ctitles = menu.getElementsByClassName('category_title')
for (var i = 0; i < ctitles.length; i++) {
var ctitle = ctitles[i]
apply_shown(ctitle, is_shown(ctitle))
@agarciadom
agarciadom / find-color-pages
Last active January 21, 2024 18:56
Small Python 2.7+ script that lists the color pages in a PDF along with their CMYK ink mixes, as computed by the 'inkcov' device in Ghostcript 9.05+. "find-color-pages file.pdf" lists the color pages and their CMYK ink mixes, "find-color-pages -c file.pdf" prints the number of color pages in the PDF and "find-color-pages -C 0.39 -B 0.04 file.pdf…
#!/usr/bin/env python
# Simple script for finding and counting the color pages in a PDF
# Copyright (C) 2013-2019 Antonio Garcia-Dominguez
# Licensed under the GPLv3
#
# This script is based on the following thread (thanks for the tip!):
#
# http://tex.stackexchange.com/questions/53493
#
@agarciadom
agarciadom / pre-commit.sh
Created March 17, 2014 20:10
SVN hook that checks that the message mentions an open ticket in a PostgreSQL-backed Redmine installation.
#!/bin/bash
# SVN hook that checks that the message mentions an open ticket in a PostgreSQL-backed Redmine installation.
# Copyright (C) 2014 Antonio García Domínguez
# Licensed under the GPLv3.
## CONFIGURATION
SVNLOOK=/usr/bin/svnlook
PSQL=/usr/bin/psql
@agarciadom
agarciadom / _.md
Last active August 29, 2015 14:06
Taller Jacathon d3.js
@agarciadom
agarciadom / _.md
Last active August 29, 2015 14:06
Ejemplo Jacathon Streamgraph
@agarciadom
agarciadom / queries.js
Last active October 7, 2015 11:42
Example queries for Hawk - IncQuery integration
// Number of an instances of a type
return %s.all.size;
// Instances of a type
return %s.all;
// Get the number of instances of an EDataType (unseeded) //////////////////////////
@agarciadom
agarciadom / blog.emf
Created January 26, 2016 11:19
Emfatic fragment for an ecore2thrift blogging service
@thrift(javans="ecore2thrift.example")
@namespace(uri="http://github.com/ecore2thrift", prefix="")
package Blog;
@doc(d="One post in the blog")
class Post {
@doc(d="Title of the post")
attr String title;
@doc(d="Date and time in ISO 8601 format")
attr String date;