Skip to content

Instantly share code, notes, and snippets.

@epitron
epitron / ean.xml
Last active January 5, 2023 04:03
Oga XML Transform feature
<HotelListResponse xmlns:ns2="http://v3.hotel.wsapi.ean.com/">
<customerSessionId>yuvb3jdpifp2t13y43pass2p</customerSessionId>
<numberOfRoomsRequested>1</numberOfRoomsRequested>
<moreResultsAvailable>false</moreResultsAvailable>
<cacheKey>-48a4e19f:15bec159775:50eb</cacheKey>
<cacheLocation>10.186.170.98:7300</cacheLocation>
<cachedSupplierResponse supplierCacheTolerance="NOT_SUPPORTED" cachedTime="0" supplierRequestNum="98" supplierResponseNum="93" supplierResponseTime="1629" candidatePreptime="28" otherOverheadTime="11" tpidUsed="5220" matchedCurrency="true" matchedLocale="true" />
<HotelList size="2" activePropertyCount="98">
<HotelSummary order="0" ubsScore="0">
<hotelId>139396</hotelId>
@epitron
epitron / ansi2html.rb
Created January 28, 2012 10:02
Convert ANSI to HTML
require 'epitools'
class State
attr_accessor :fore, :back, :attrs
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
ATTRS = {
0 => :reset,
@epitron
epitron / primes.py
Last active April 20, 2021 07:42
Fast prime number generators in Python
#!/usr/bin/env python3
from itertools import islice
from time import time
def time_generator(func, n=500000):
generator = func()
start = time()
islice(generator, n)
elapsed = time() - start
@epitron
epitron / 1_smtpd.rb
Created January 4, 2009 03:29
A 77 line SMTP server, and a 253 line POP3 server.
require 'gserver'
require 'rubygems'
require 'active_record'
dbconfig = YAML::load_file(File.dirname(__FILE__) + '/config/database.yml')
ActiveRecord::Base.establish_connection(dbconfig['development'])
# CREATE TABLE emails (id integer primary key autoincrement, mail_from, rcpt_to, subject, email, user_id integer);
# CREATE TABLE users (id integer primary key autoincrement, username, password, email);
@epitron
epitron / kv_bench.rb
Last active May 18, 2020 05:21
Benchmark Ruby's various key/value databases (GDBM, SDBM, CDB)
require 'epitools'
%w[gdbm sdbm cdb].each { |lib| require lib }
DBS = [
[GDBM, GDBM],
[SDBM, SDBM],
[CDBMake, CDB ],
]
NUM = 100000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include <linux/uinput.h>
#define die(str, args...) do { \
Name 8ZYQ1474W7: Sodium Fluoride (Fluoride Ion) C810JCZ56Q: Sodium Monofluorophosphate (Fluoride Ion) RU45X2JN0Z: Potassium Nitrate (Nitrate Ion) 4NM5039Y5X: Triclosan (Triclosan) 059QF0KO0R: Water 15FIX9V2JP: Titanium Dioxide 1E2MCT2M62: Zinc Phosphate 1K09F3G675: Ferric Oxide Red 1P9D0Z171K: Butylated Hydroxytoluene 1VPU26JZZ4: Potassium Sorbate 229D0E1QFA: Methylisothiazolinone 22ADO53M6F: Sodium Phosphate, Dibasic, Anhydrous 2968PHW8QP: Citric Acid Monohydrate 2P3VWU3H10: Activated Charcoal 35SW5USQ3G: D&C Yellow No. 10 368GB5141J: Sodium Lauryl Sulfate 389H2R62BD: Butyl Ester of Methyl Vinyl Ether/Maleic Anhydride Copolymer (125000 Mw) 3P3ONR6O1S: Fd&C Green No. 3 3SCV180C9W: Betaine 3T8H1794QW: Eugenol 3WJQ0SDW1A: Polyethylene Glycol 4ERD2076EF: Peg-40 Castor Oil 4GFU244C4J: Methylcellulose (100 Mpa.S) 506T60A25R: Sorbitol 54S8C1184Z: Zinc Phosphate Tetrahydrate 55X04QC32I: Sodium Hydroxide 593YOG76RN: Sodium Phosphate, Monobasic, Monohydrate 5C69YCD2YJ: Carrageenan 5HK03SA80J: Sodium Tripolyphospha
@epitron
epitron / http_client.rb
Created April 6, 2014 20:44
A wrapper around Mechanize which implements a caching HTTP client that doesn't blow up if it hits an error pages (like 404).
require 'mechanize'
require 'logger'
require_relative 'random_agent'
require_relative 'path'
# Mechanize::Page subclasses Mechanize::File, Mechanize::Download is its own thing
# module MimeInfo
# def size
# header["content-length"].to_i
@epitron
epitron / background.js
Created October 17, 2014 18:38
Sample Chrome Extension
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.commands.onCommand.addListener(function(command) {
console.log('onCommand event received for message: ', command);
});
@epitron
epitron / activerecord-benchmarks.csv
Last active March 4, 2018 21:48
CockroachDB vs PostgreSQL vs MySQL vs SQLite
activerecord-cockroachdb activerecord-postgresql activerecord-mysql activerecord-sqlite Benchmark
9.216770* (60720k) 9.590111 (60984k) 12.455487 (69168k) 18.465701 (64944k) Model Object Creation: 3200 objects (No Transaction)
0.900417 (0k) 0.893337 (0k) 0.832904 (0k) 0.707108* (0k) Model Object Creation: 3200 objects (Transaction)
2.031437* (337128k) 2.070499 (336864k) 2.181665 (332112k) 2.215748 (333432k) Model Object Select: 6400 objects 64 times (No Transaction)
2.004822 (0k) 1.984105* (0k) 2.121498 (264k) 2.175031 (0k) Model Object Select: 6400 objects 64 times (Transaction)
3.460825 (0k) 3.337974 (0k) 3.875209 (0k) 2.622881* (0k) Model Object Select PK: 640 objects 64 times (No Transaction)
3.372082 (0k) 3.247312 (0k) 3.786783 (0k) 2.253132* (0k) Model Object Select PK: 640 objects 64 times (Transaction)
3.594136 (0k) 3.431209 (0k) 4.428752 (0k) 2.679963* (0k) Model Object Select Hash: 640 objects 64 times (No Transaction)
3.473371 (0k) 3.358583 (0k) 3.800874 (0k) 2.409768* (0k) Model Object Select Hash: