Skip to content

Instantly share code, notes, and snippets.

@francisco-perez-sorrosal
francisco-perez-sorrosal / moving_box.html
Created September 22, 2011 20:33
My html containing the moving box Javascript example implemented in class with Carlos Benítez (Madrid, 14/Sep/2011)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
body{background-color:#ccc}
#box{
width:100px;
@francisco-perez-sorrosal
francisco-perez-sorrosal / CurrencyParser.scala
Created November 5, 2011 03:58
Program that parses a remote XML file containing info about currencies and outputs a new user-defined format for the parsed data in a new file (passed as parameter)
package com.linkingenius.parser
import java.io.File
import java.io.FileWriter
// Handler to perform write operations in a file
case class FileHandler(file: File) {
def add(text: String): Unit = {
val fw = new FileWriter(file, true)
private static String translateToProteins(String dna) {
String result = "";
int idx = dna.indexOf(START_CODON, 0);
while (idx < dna.length() && idx != -1) {
String dnaChunk = dna.substring(idx, idx + 3);
if (dnaChunk.equals(END_CODON_1) || dnaChunk.equals(END_CODON_2)
|| dnaChunk.equals(END_CODON_3)) {
idx = dna.indexOf(START_CODON, idx);
@francisco-perez-sorrosal
francisco-perez-sorrosal / SpiralMatrix.java
Created December 22, 2011 12:06
Code that traverses a matrix in spiral using recursion and a simple state machine.
public class SpiralMatrix {
enum Direction {
LEFT_RIGHT, TOP_DOWN, RIGHT_LEFT, BOTTOM_UP
};
public static void traverseMatrixInSpiral(char[][] matrix, int initialRow,
int finalRow, int initialColumn, int finalColumn, int totalElems,
int visited, Direction direction) {
System.out.println("Num Elems: " + totalElems + " visited: " + visited);
@francisco-perez-sorrosal
francisco-perez-sorrosal / LinkedListLoopDetector.java
Created January 23, 2012 15:38
Code to detect loops in linked lists in O(n)
public static boolean containsLoop(LinkedListNode list) {
LinkedListNode slowIterator = list, fastIterator = list;
// If a loop exists in the list, both iterators will be going round
// and round in the loop, and at some point, they will be equal
while (slowIterator != null && fastIterator != null) {
slowIterator = slowIterator.getNext();
try {
fastIterator = fastIterator.getNext().getNext();
} catch (NullPointerException npe) {
fastIterator = null;
@francisco-perez-sorrosal
francisco-perez-sorrosal / MainDigester
Created June 11, 2012 00:23
MessageDigest algorithm response times
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MainDigester {
public enum Digester {
SHA512("SHA-512"),
@francisco-perez-sorrosal
francisco-perez-sorrosal / sort.sh
Last active August 29, 2015 14:05
Command to sort and pretty print a column-based text file in UNIX
sort -nr -t$'\t' -k<column> <file> | column -ts $'\t'
@francisco-perez-sorrosal
francisco-perez-sorrosal / change_git_committer_data.sh
Created August 2, 2016 07:55
Change the committer/author data in Git
#!/bin/sh
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "Francisco Perez-Sorrosal" ];
then
GIT_COMMITTER_NAME="Francisco Perez-Sorrosal";
GIT_AUTHOR_NAME="Francisco Perez-Sorrosal";
GIT_COMMITTER_EMAIL="fperezsorrosal@gmail.com";
GIT_AUTHOR_EMAIL="fperezsorrosal@gmail.com";
git commit-tree "$@";
# Generate dep graph in maven
mvn org.fusesource.mvnplugins:maven-graph-plugin:reactor -Dhide-external=true
@francisco-perez-sorrosal
francisco-perez-sorrosal / Makefile.rsync
Created January 18, 2019 19:45
Makefile for Rsync
# Local-Remote synchronization of directories/files
# NOTE: Deletions are NOT considered yet.
# Usage
# -----
# Local-remote sync:
# make -f Makefile.rsync lrsync SERVER=my_host PROJECT=project_name LOCAL_BASEDIR=/Users/my_name/dev REMOTE_BASEDIR=/home/my_name/dev
#
# Remote-local sync:
# make -f Makefile.rsync rlsync SERVER=my_host PROJECT=project_name LOCAL_BASEDIR=/Users/my_name/dev REMOTE_BASEDIR=/home/my_name/dev