Skip to content

Instantly share code, notes, and snippets.

@minoki
minoki / foo.cpp
Last active August 29, 2015 14:13
#include <cstdio>
class Foo
{
int x;
public:
Foo(int x);
~Foo();
void greet();
};
Foo::Foo(int x) : x(x)
@minoki
minoki / gist:2732f2d723ef0816fc8e
Created January 18, 2015 11:29
An example of the coproduct type in TypeScript
interface Sum<A,B>
{
elim<C>(left: (value: A) => C, right: (value: B) => C): C;
}
function Left<A>(value: A): {elim<C>(left:(value:A)=>C,right:(value:any)=>C):C;}
{
return {
elim: <C>(left: (value: A) => C, right: (value: any) => C) => left(value)
};
}
@minoki
minoki / qrcode-test.hs
Created May 18, 2015 09:18
An example program using haskell-qrcode library.
import qualified Codec.Binary.QRCode as Q -- from `qrcode' package
import qualified Codec.Picture as P -- from `JuicyPixel' package
import qualified Codec.Picture.Png as P
import qualified Data.ByteString.Lazy as B
import Data.Array (Array,bounds,(!))
pixelPerCell = 5
main :: IO ()
main = do l <- getLine
@minoki
minoki / qrencode-test.hs
Created May 18, 2015 09:31
An example program using haskell-qrencode library.
import qualified Data.QRCode as Q -- from `haskell-qrencode' package
import qualified Codec.Picture as P -- from `JuicyPixels' package
import qualified Codec.Picture.Png as P
import qualified Data.ByteString.Lazy as B
pixelPerCell = 5
main :: IO ()
main = do l <- getLine
let version = Nothing -- auto
@minoki
minoki / Better_MyOPAC.user.js
Last active August 31, 2015 05:24
MyOPACのログインフォームを改善したりいろいろ
// ==UserScript==
// @name Better MyOPAC
// @namespace http://d-poppo.nazo.cc/
// @description MyOPACのログインフォーム等を改善する
// @include https://opac.dl.itc.u-tokyo.ac.jp/myopac/
// @include https://opac.dl.itc.u-tokyo.ac.jp/myopac/index.php*
// @include https://opac.dl.itc.u-tokyo.ac.jp/opac/opac_list.cgi
// @include https://opac.dl.itc.u-tokyo.ac.jp/optsrv/opac_list.php*
// @version 5
// @grant none
require "cocoa"
local filename = arg[1]
if not filename then
return
end
local ishtml = false
if filename:match("%.html$") then
ishtml = true
local assert,error,setmetatable,tonumber = assert,error,setmetatable,tonumber
local table = require "table"
local io = require "io"
local lxp = require "lxp"
local base64 = require "base64"
module "propertylist"
array_metatable = {}
dictionary_metatable = {}
var CSSMatrix;
if (navigator.userAgent.indexOf("Gecko") !== -1 && navigator.userAgent.indexOf("KHTML") === -1) {
CSSStyleDeclaration.prototype.__defineGetter__("borderRadius",function() {
return this.MozBorderRadius;
});
CSSStyleDeclaration.prototype.__defineSetter__("borderRadius",function(x) {
this.MozBorderRadius = x;
});
CSSStyleDeclaration.prototype.__defineGetter__("userSelect",function() {
/*
bind1 :: (a -> b) -> a -> b
bind1 f t0 = f t0
*/
template<typename R, typename F, typename T0>
struct bind1_impl {
bind1_impl(F f,T0 t0):f(f),t0(t0){}
template<typename... T>
R operator()(T... t) {
return static_cast<R>(f(t0, t...));
// gcd a b | a`mod`b == 0 = b
// | otherwise = gcd b (a`mod`b)
#define GCD(a,b) (GCD1((a),(b)))
#define GCD1(a,b) a%b==0?b:GCD2(b,(a%b))
#define GCD2(a,b) a%b==0?b:GCD3(b,(a%b))
#define GCD3(a,b) a%b==0?b:GCD4(b,(a%b))
#define GCD4(a,b) a%b==0?b:GCD5(b,(a%b))
#define GCD5(a,b) a%b==0?b:GCD6(b,(a%b))