This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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'>" + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <queue> | |
#include <iostream> | |
#include <cstdlib> | |
#include <ctime> | |
using namespace std; | |
void benchmark(int len) | |
{ | |
priority_queue<int> q; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bisect import bisect_left | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
import autograd.numpy as np | |
from autograd import grad | |
def fn(a, b): | |
return np.sum(a @ b) | |
n = 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import theano | |
import theano.tensor as T | |
# Steepest descent method using theano.scan() | |
def fn(x, learning_rate): | |
y = x ** 2 - x | |
return x - learning_rate * T.grad(y, x) | |
init_x = T.dscalar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import theano | |
import theano.tensor as T | |
# AdaGrad using theano.scan() | |
def fn(x, r, learning_rate): | |
y = x ** 2 - x | |
g = T.grad(y, x) | |
r += g ** 2 | |
return x - learning_rate / T.sqrt(r) * g, r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import theano | |
import theano.tensor as T | |
from theano.tensor.shared_randomstreams import RandomStreams | |
# AdaGrad + stochastic gradient descent using theano.scan() | |
train_x = np.random.rand(100) | |
train_y = train_x + np.random.rand(100) * 0.01 |
OlderNewer