Skip to content

Instantly share code, notes, and snippets.

@jmora
jmora / compress.py
Created December 27, 2019 12:43
Compress files (I need to use this somewhere else)
#!/usr/bin/python3
import os, shutil, sys, subprocess
p = lambda *e: '/'.join(e)
def bash (*command):
c = ' '.join(command)
print('Doing ', c)
subprocess.Popen(c, stderr=sys.stdout, stdout=sys.stdout, shell=True).wait()
@jmora
jmora / 0README.md
Last active August 29, 2015 14:21
README

In reference to a post comparing programming languages.

I did two versions, the first one is closer to the original, the second one is more efficient and nicer IMHO.

I have been thinking about choosing "the best programming language" for a while, for a number of reasons, including long term DRY.

@jmora
jmora / Operations.java
Last active August 29, 2015 14:14
An example of the modifications needed to parallelize something (using futures) in Java and Scala (check the diff).
package tests.javafuture;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class Operations {
private final int cores = Runtime.getRuntime().availableProcessors();
@jmora
jmora / context.tex
Created November 15, 2013 18:23
A friend requested this slide, it took some time to ensure all the dependencies are there (there may be some unnecessary dependencies). Since I spent some time on this and it's more than 100 lines, I thought I would put it here.
\documentclass[xcolor={x11names, table},table,compress,10pt]{beamer}
\usepackage{varwidth, graphicx, tikz, palatino}
\usetikzlibrary{arrows,shapes.geometric,positioning}
\definecolor{oegred}{RGB}{153,0,0}
\definecolor{oegblu}{RGB}{0,0,153}
% http://tex.stackexchange.com/questions/103688/folded-paper-shape-tikz
\makeatletter
@jmora
jmora / pdfize.tex
Created September 20, 2013 10:53
I scanned a document recently and I wanted to put all the images into a PDF as a coherent document. This may be very simple with Adobe Acrobat, but it's expensive and I didn't have it available. It turns out it's very simple with LaTeX too so this is what I did:
\documentclass{article}
\usepackage{graphicx}
\usepackage[margin=-0.01cm]{geometry}
\begin{document}
\includegraphics{image_1}
\includegraphics{image_2}
% ...
\includegraphics{image_n}
\end{document}
@jmora
jmora / kata_tenis.html
Created October 6, 2012 23:14
Kata tenis.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
table {border-collapse: collapse; border: 1px solid #000;}
</style>
<script>
var counter = {
texts: ['0', '15', '30', '40'],
specials: ['40, pierde', '40', 'deuce', 'ventaja', 'gana'],
@jmora
jmora / sudoku.pl
Created June 30, 2012 16:00
This is a prolog sudoku solver I coded years ago and found back minutes ago.
author('@j_mora').
:- use_package(clpq).
numbers([1,2,3,4,5,6,7,8,9]).
myMember(E, [E|Ls], Ls).
myMember(E, [L|Ls], [L|Rs]):- myMember(E, Ls, Rs).
sudoku(X):- numbers(Ns), squares(X), columns(X), rows(X, Ns).
@jmora
jmora / countWords.py
Created May 30, 2012 11:08
Short script to count how many times words appear on a file, you may need to change the re
#!/usr/bin/python3
import re, sys
if __name__ == "__main__":
c = {}
with open(sys.argv[1], "r") as f:
for l in f:
for e in re.findall("\w+", l):
c[e] = c.get(e, 0) + 1
for e in sorted(c.items(), key=lambda i:i[1], reverse=True):
@jmora
jmora / Hospital.ttl
Created March 27, 2012 16:35
Small real-like ontology about Hospitals. There is a mistake, try to find it!
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix : <http://github.com/jmora/ontologies/Hospital.owl#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@base <http://github.com/jmora/ontologies/Hospital.owl> .
<http://github.com/jmora/ontologies/Hospital.owl> rdf:type owl:Ontology .
@jmora
jmora / yearTable.py
Created January 31, 2012 15:42
This is a short script I wrote years ago to generate a table in mediawiki. I think I'll keep it here, it's easier to find when moving between computers.
#!/usr/bin/env python
import datetime
import sys
weekday = 3 #3 = Thursday, change it if you will, Monday == 0
def englishMonth(n): #this has to be defined somewhere, but I cannot find it now
l = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December']