Skip to content

Instantly share code, notes, and snippets.

View ishikawa's full-sized avatar
🏠
Working from home

Takanori Ishikawa ishikawa

🏠
Working from home
View GitHub Profile
@ishikawa
ishikawa / gist:88599
Created April 1, 2009 07:49
Java Sample Code for Calculating HMAC-SHA1 Signatures
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.util.Formatter;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
/**
@ishikawa
ishikawa / MyTextView.h
Created November 8, 2008 10:28
Cocoa custom text view with managing marked text
#import <Cocoa/Cocoa.h>
@interface MyTextView : NSView <NSTextInput, NSTextInputClient> {
NSMutableAttributedString *_text;
NSRange _selectedRange;
NSRange _markedRange;
}
@end
@ishikawa
ishikawa / dominance_frontiers.rb
Created February 18, 2011 07:19
A Simple, Fast Dominance Algorithm
# Cooper, Keith D.; Harvey, Timothy J.; and Kennedy, Ken (2001). A Simple, Fast Dominance Algorithm
# http://www.cs.rice.edu/~keith/EMBED/dom.pdf
#
# Computing minimal SSA using dominance frontiers
# http://en.wikipedia.org/wiki/Static_single_assignment_form#Computing_minimal_SSA_using_dominance_frontiers
#
# Dominator (graph theory)
# http://en.wikipedia.org/wiki/Dominator_(graph_theory)
#
require 'set'
@ishikawa
ishikawa / ycombinator.py
Created May 21, 2011 03:21
Y Combinator in Python
# Y Combinator in Python
# See <http://d.hatena.ne.jp/nowokay/20090409#1239268405>
true = lambda x: lambda y: x
false = lambda x: lambda y: y
# `bool` to `true|false`
#
# >>> boolean(3 < 4)(2)(5)
# 2
@ishikawa
ishikawa / gist:35056
Created December 12, 2008 08:46
reStructuredText: How to use nested inline markup using substitutions with the "replace" directive
|Wall|_
.. |Wall| replace:: ``-Wall``
.. _Wall: http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Warning-Options.html#index-Wall-234
@ishikawa
ishikawa / gist:47af9f5dd4040cd33bcdbace7c97f5b3
Last active November 20, 2022 08:29
Profiling whisper with English audio file (2.1 mb) / large model / cpu
Sun Nov 20 14:40:09 2022 whisper.prof
5912402 function calls (5549784 primitive calls) in 709.208 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1983/1 0.038 0.000 709.211 709.211 {built-in method builtins.exec}
1 0.086 0.086 709.195 709.195 prof_whisper.py:1(<module>)
1 0.024 0.024 673.748 673.748 transcribe.py:19(transcribe)
@ishikawa
ishikawa / uint16_to_int16.t
Created December 14, 2009 12:20
How to convert 16 bit unsigned integer to 16 bit signed integer in Perl
use strict;
use warnings;
use Test::More qw(no_plan);
sub uint16_int16 {
my $v = shift;
return ($v & 0x8000) ? -((~$v & 0xffff) + 1) : $v;
}
@ishikawa
ishikawa / solve.py
Created July 17, 2021 22:40
"The Art and Craft of Problem Solving" 1.1.3
combinations = set()
for x in range(1, 37):
for y in range(1, 37):
for z in range(1, 37):
if x * y * z == 36:
sisters = [x, y, z]
sisters.sort(reverse=True)
sisters = tuple(sisters)
if sisters not in combinations:
@ishikawa
ishikawa / enum_str.rs
Created July 17, 2021 22:39
Rust: Converting between Enums and Strings
pub enum Foo {
A,
B,
}
impl Foo {
pub fn variants() -> impl Iterator<Item = Foo> {
array::IntoIter::new([Self::A, Self::B])
}
}
@ishikawa
ishikawa / index.ts
Created January 29, 2021 00:53
The node implementation for expo-crypto
/*
MIT License
Copyright (c) 2021 Takanori Ishikawa
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is