Skip to content

Instantly share code, notes, and snippets.

@josejuan
josejuan / reduccion.asm
Created July 2, 2012 17:55
reducción asm
# compiled with: gcc (GCC) 4.7.1
# $ gcc -O3 -S file.c
# only relevant lines
mod4:
...
andl $3, %eax
ret
div4:
WITH Acc AS (
SELECT s70.ord,
song70Id = s70.songId,
song80Id = s80.songId,
song90Id = s90.songId,
roundTime = s70.songTime + s80.songTime + s90.songTime
FROM (SELECT ord = Row_Number() OVER(ORDER BY songTime DESC),
songId,
songTime
FROM @songList
@josejuan
josejuan / microProber.html
Created July 10, 2012 20:35
micro probador de teoremas
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Micro Verificador de Teoremas</title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
function MicroVerificador(reglas, consultas) {
var w = ["siempre_que", "no", "y", "o", "implica_que", "cierto", "falso", "(", ")"];
var clear = function(s){
@josejuan
josejuan / MicroVerificador.js
Created July 11, 2012 06:58
MicroVerificador
function MicroVerificador(reglas, consultas) {
var w = ["siempre_que", "no", "y", "o", "implica_que", "cierto", "falso", "(", ")"];
var clear = function(s){
return $(s.replace(/\(/g, " ( ").replace(/\)/g, " ) ").split('\n')).
filter(function(){return this.trim() != ""}).get()};
var r = clear(reglas), c = clear(consultas);
var v = [], S = [], R = [];
$(r.join(' ').split(' ')).each(function () {
var z = this.trim();
if(z != "" && $.inArray(z, w) < 0 && $.inArray(z, v) < 0)
@josejuan
josejuan / string2hash.php
Created July 18, 2012 09:37
PHP string to hash
array_reduce( explode($rowSeparator, $inputString),
function($a, $x) {
global $colSeparator;
$r = explode($colSeparator, $x);
return $a + array(array_shift($r) => $r);
}, array())
// dado "12,pepe,2012;56,juan,2011"
// devuelve array(12 => array("pepe", 2012), 56 => array("juan", 2011))
qsort (p:xs) = qsort [x | x<-xs, x<p] ++ [p] ++ qsort [x | x<-xs, x>=p]
@josejuan
josejuan / qsort2.hs
Created July 18, 2012 10:06
qsort 2
sort = sortBy compare
sortBy cmp = mergeAll . sequences
where
sequences (a:b:xs)
| a `cmp` b == GT = descending b [a] xs
| otherwise = ascending b (a:) xs
sequences xs = [xs]
descending a as (b:bs)
| a `cmp` b == GT = descending b (a:as) bs
@josejuan
josejuan / agc.pl
Created July 19, 2012 09:09
anonymous grid computing
#!/usr/bin/perl
use strict;
use bigint;
print "Cache-Control: no-cache\n";
print "Content-type: text/html\n";
print "\n";
my $data = '/ruta/del/archivo/de/datos/agc.dat';
@josejuan
josejuan / anonymousGridComputing.html
Created July 19, 2012 09:16
anonymousGridComputing.html
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Anonymous Grid Computing</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
// se produce cuando un hilo a acumulado suficientes datos
function RegisterData(msg) {
// mostramos el resultado
$('#PiDigits').html(
// Calculamos Pi enviando datos cada X tiempo
function Pi(MaxMilliSegs) {
var T, H, t, r = 0;
var rst = function () {
T = H = 0;
t = MaxMilliSegs + ~~new Date();
};
rst();
while(1) {
// para no andar mirando el tiempo