Skip to content

Instantly share code, notes, and snippets.

View ucarion's full-sized avatar
🌁
I just love enterprise software, man

Ulysse Carion ucarion

🌁
I just love enterprise software, man
View GitHub Profile
@ucarion
ucarion / html_cleanup.rb
Last active December 26, 2024 03:46
Composing programs to PDF
require 'nokogiri'
input = $stdin.readlines.join
page = Nokogiri::HTML(input)
page.css('.example').each do |elem|
elem.inner_html = '<i>Environment diagram omitted.</i>'
end
page.css('img').remove
@ucarion
ucarion / cah.txt
Created October 4, 2014 00:46
Cards Against Humanity Haikus
Flying sex snakes.
Michelle Obama's arms.
German dungeon porn.
White people.
Getting so angry that you pop a boner.
Tasteful sideboob.
Praying the gay away.
Two midgets shitting into a bucket.
MechaHitler.
Being a motherfucking sorcerer.
@ucarion
ucarion / hog.hs
Created September 17, 2014 20:40
Pig score distributions
-- Execute this as:
--
-- ghc -O2 hog.hs && ./hog
--
-- Which takes about 1 minute to execute.
import Data.List (any)
import Control.Monad (replicateM)
rolls :: Int -> Int -> [[Int]]
@ucarion
ucarion / asdf.py
Created May 20, 2014 06:54
Same thing, but in Python
import copy
import random
people = [0, 1, 2, 3, 4, 5, 6, 7]
tries = 1000000
count = 0
for _ in range(tries):
shuffled_people = copy.copy(people)
random.shuffle(shuffled_people)
@ucarion
ucarion / asdf.rb
Created May 20, 2014 04:33
Random-sorting 8-groups
people = (0...8).to_a
tries = 10_000_000
count = 0
tries.times do
if people.shuffle.each_with_index.all? { |person, index| person != index }
count += 1
end
end
p count.to_f / tries
@ucarion
ucarion / JOptionPane.java
Created February 17, 2014 02:38
Custom JOptionPane class
package javax.swing;
import java.util.Scanner;
import java.awt.Component;
/**
* This is a fake JOptionPane class. It overrides the two most commonly-used
* JOptionPane-based functions for IO (#showInputDialog and #showMessageDialog)
* and has them simply use System.in and System.out.
*
@ucarion
ucarion / benchmark.rb
Created January 26, 2014 07:47
Performance of array-averaging in Ruby vs. C
require 'benchmark'
require 'extension_cord'
def average_reduce(arr)
arr.reduce(:+).to_f / arr.size
end
def average_upto(arr)
sum = 0
@ucarion
ucarion / bash_docker.rb
Created August 22, 2013 03:30
Call Docker image through bash
require 'docker'
require 'shellwords'
image = Docker::Image.all.first
s = IO.read('tmp.rb').shellescape
cmd = [ "/bin/bash", "-c", "echo #{s} > roobee.rb; ruby roobee.rb" ]
puts "Response from Docker: "
@ucarion
ucarion / DistanceQuerySearchTool.java
Last active December 21, 2015 02:19
How the project works
package org.pdb.query.simple.distance;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.biojava.bio.structure.Element;
@ucarion
ucarion / dirmagic.sh
Created August 6, 2013 23:11
Count number of files in each subdirectory from '.'
for dir in */
do
find ./$dir -type f | wc -l
done