Skip to content

Instantly share code, notes, and snippets.

@yukoba
yukoba / test_two_queues.py
Last active November 5, 2015 10:41
Facebookに書いた複数のキューから優先度の合計の最小を取ってくるやつ(この実装はpq1への動的追加で失敗します)
from heapq import heapify, heappop, heappush
from itertools import islice
from sys import maxsize
# サンプルデータ
pq0 = [(1, "a"), (2, "b"), (3, "f")]
pq1 = [(1, "c"), (2, "d"), (3, "g")]
heapify(pq0)
heapify(pq1)
@yukoba
yukoba / Benchmark.groovy
Last active August 29, 2015 14:16
Boxing benchmark
import groovy.transform.CompileStatic
import org.junit.Test
@CompileStatic
class Benchmark {
@Test
void test1() {
int[] ary = new int[1024 * 1024]
for (int i = 0; i < ary.length; i++) {
ary[i] = i
#include <queue>
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void benchmark(int len)
{
priority_queue<int> q;
@yukoba
yukoba / SVGinCanvas.html
Created November 5, 2012 13:10
SVG in Canvas
<!DOCTYPE html>
<html>
<body>
<p><canvas id="canvas" style="border:2px solid black;" width="200" height="200"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" +
"<foreignObject width='100%' height='100%'>" +
"<div xmlns='http://www.w3.org/1999/xhtml' style='font-size:40px'>" +
@yukoba
yukoba / MD5Utils.java
Created November 4, 2012 12:12
MD5 Java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Utils {
public static String convert(String s) {
try {
// Create MD5 Hash
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();