Skip to content

Instantly share code, notes, and snippets.

View JJ's full-sized avatar
🏠
Working from home

Juan Julián Merelo Guervós JJ

🏠
Working from home
View GitHub Profile
@JJ
JJ / equipo.xml
Created July 13, 2011 07:48
Pretty-print XML files with user-specified colors and indents
?xml version="1.0"?>
<?xml-stylesheet href="tienda0.xsl" type="text/xsl"?>
<equipo>
<jugador posicion='portero'>Araña</jugador>
<jugador posicion='delantero'>Cazagoles</jugador>
</equipo>
@JJ
JJ / csv_to_net.pl
Created October 24, 2011 12:29
Convert CSV files to Pajek .net format. Takes file with two columns as argument; every row indicates a connection from agent in column A to agent in Column B. Outputs a file with the same root and .net extension in .net format, which can be used in Pajek
#!/usr/bin/perl
use strict;
use warnings;
use File::Slurp qw(read_file);
my $csv = shift || die "No defaults; $0 <csvfile>\n";
my $content = read_file($csv) || die "Can't read file $csv: $!\n";
@JJ
JJ / jquery-test.js
Created January 25, 2012 11:15
Prueba con JQuery para el taller de Ajax de la OSLUGR. Un ejemplo mínimo de uso de Ajax con JQuery
$(function(){
$("a.ajax").click((function(){
$.get($(this).attr('href'), function(data){
alert("Ya");
})
.success(function(data){
alert( 'Lo hise' )})
.error(function(data){
alert( 'Pos no' )})
.complete(function(data){
@JJ
JJ / compare_strings_mastermind.c
Last active December 10, 2015 17:18
Compare two strings returning the number of symbols in the correct position ("blacks") and the number of symbols in the wrong position ("whites"), MasterMind style
#include <stdio.h>
#include <string.h>
// with help from http://www.eskimo.com/~scs/cclass/notes/sx13.html
int main( int argc, char *argv[] )
{
char *hidden = argv[1];
char *target = argv[2];
char colors = atoi( argv[3] );
printf( "Hidden %s target %s colors %d\n", hidden, target, colors);
@JJ
JJ / citations.user.js
Created April 20, 2013 09:43
GreaseMonkey script that puts on top of the citation graph the actual number of citations per year; works on the Google Citations page. In old versions of Chrome and Chromium this should work without a problem. In new versions you'll have to get out of your way to install it, so don't bother and just switch to Firefox and install the GreaseMonke…
// ==UserScript==
// @name gcitations
// @namespace http://merelo.net/gmscripts
// @description Compute number of citations per year in Google Citations
// @include http://scholar.google.com/citations*
// ==/UserScript==
var imgs = document.getElementsByTagName('img');
var my_url;
@JJ
JJ / git-hooks.pl
Created August 26, 2013 17:07
Git post-commit hook for modifying .md files to work with gh-pages and just copy other files, like .png, .css and so on.
#!/usr/bin/env perl
use strict;
use warnings;
use v5.14;
use Git::Hooks;
use File::Slurp qw(read_file write_file);
my $layout_preffix=<<EOT;
---
@JJ
JJ / node-and-npm-in-30-seconds.sh
Last active January 3, 2016 11:59 — forked from isaacs/node-and-npm-in-30-seconds.sh
Installing node in a very raw box (like the one provided by docker). It will take a bit more than 30 seconds, somehow
#Problem with this is that it needs lots of installed stuff, so I'll put it here
# sudo or admin shell is presupposed
apt-get install make curl python-setuptools gcc g++
#Maybe you can safely supress make and gcc from here, since they are dependencies of g++
#Then you can proceed to the original set
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir /usr/local
mkdir ~/node-latest-install
@JJ
JJ / chef-solo.sh
Created January 24, 2014 07:27
Provisioning chef-solo for ArchLinux 2013
pacman -S ruby make gcc
gem install chef ohai --no-user-install
@JJ
JJ / wilcoxon-ga.chunk.pl
Last active August 29, 2015 13:57
Applying Wilcoxon-comparison based partial order to an evolutionary algorithm
for my $p ( @pop ) {
push(@{$p->{'_fitness_memory'}}, $noisy->apply( $p ));
$p->Fitness($comparisons);
}
for my $i (1..$comparisons) {
my @copy_of_population = @pop;
while( @copy_of_population ) {
my $first = splice( @copy_of_population, rand( @copy_of_population ), 1 );
my $second = splice( @copy_of_population, rand( @copy_of_population ), 1 );
my $aov = Statistics::ANOVA->new();
@JJ
JJ / install_Git.pm.md
Last active January 6, 2017 11:32
Install Git.pm in a perlbrew installation

Git.pm is a module that comes with git and can't be installed with the usual cpan magic. If you switch to perlbrew you'll get a Can't locate Git.pm error when you try to run it, so you need to install it explicitly if you want to use it in your own installation, mainly if you use perlbrew I use it in my novels for post-commit hooks, so here's what you have to do to have it available in your programs

bash$ cp /usr/share/perl5/Git.pm ~/perl5/perlbrew/perls/perl-5.x.y/lib/site_perl/5.x.y

you'll have to change x.y by the perl version you're actually using. You'll also need Error.pm, so do

bash$ cp /usr/share/perl5/Error.pm ~/perl5/perlbrew/perls/perl-5.x.y/lib/site_perl/5.x.y

And that's it!