Skip to content

Instantly share code, notes, and snippets.

View yoshiki's full-sized avatar

Yoshiki Kurihara yoshiki

View GitHub Profile
#include <openssl/hmac.h>
#include <string.h>
#include <stdio.h>
int main()
{
unsigned char *key = (unsigned char*)"This is your secret";
unsigned char *data = (unsigned char*) "hoge";
unsigned char *expected = (unsigned char*) "4a7bc6c59ebc1a83dc38ec4fd537f98994a9210bf09ad9fc8c60c2ae83746d82";
unsigned char *result;
import Data.Char (ord)
import Data.Bits
base64 :: String -> String
base64 "" = ""
base64 xs = indexToChar (concat24Bits xs) ++ padding xs
concat24Bits :: String -> [Int]
concat24Bits (x:[]) =
let n = shiftL (ord x::Int) 16
bswap [x] = [x]
bswap (x:y:zs)
| x < y = y : bswap (x:zs)
| otherwise = x : bswap (y:zs)
bsort :: (Ord a) => [a] -> [a]
bsort [] = []
bsort [x] = [x]
bsort xs = y : bsort ys
where
fib :: Int -> [Integer]
fib 0 = error "arg >= 1"
fib 1 = [1]
fib 2 = fib 1 ++ [1]
fib n = xs ++ [x + y]
where xs = fib (n - 1)
(x:y:_) = reverse xs
#!/usr/bin/env perl \
use strict;
my $DEBUG = 0;
main();
sub main {
my $win = 0;
@yoshiki
yoshiki / gist:7702073
Created November 29, 2013 05:58
2つの線の間の角度を求める関数。 originを頂点としたinitialとcurrentに引かれた線の間の角度を求められる。
+ (CGFloat)angleWithOrigin:(CGPoint)origin initial:(CGPoint)initial current:(CGPoint)current {
CGFloat initialAngle = atan2(initial.y - origin.y, initial.x - origin.x);
CGFloat currentAngle = atan2(current.y - origin.y, current.x - origin.x);
return currentAngle - initialAngle;
}
@yoshiki
yoshiki / gist:7702066
Created November 29, 2013 05:55
2つの線の交点座標を求める関数。 線分が交わっていないとCGPointZeroが返る。 もし線分関係なしに延長線上に交点があるのかを求める場合は7〜10行目をコメントアウトすればよい。
+ (CGPoint)intersectionOfLineFrom:(CGPoint)p1 to:(CGPoint)p2 withLineFrom:(CGPoint)p3 to:(CGPoint)p4 {
CGFloat d = (p2.x - p1.x)*(p4.y - p3.y) - (p2.y - p1.y)*(p4.x - p3.x);
if (d == 0)
return CGPointZero; // parallel lines
CGFloat u = ((p3.x - p1.x)*(p4.y - p3.y) - (p3.y - p1.y)*(p4.x - p3.x))/d;
CGFloat v = ((p3.x - p1.x)*(p2.y - p1.y) - (p3.y - p1.y)*(p2.x - p1.x))/d;
if (u < 0.0 || u > 1.0)
return CGPointZero; // intersection point not between p1 and p2
if (v < 0.0 || v > 1.0)
return CGPointZero; // intersection point not between p3 and p4
@yoshiki
yoshiki / register.pl
Created December 7, 2011 04:50
Perl scripts for im.kayac.com
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent::XMPP::Client;
use AnyEvent;
use Config::Pit;
use Encode;
use constant DEBUG => 0;
@yoshiki
yoshiki / pom.xml
Created October 13, 2011 02:29
Maven pom.xml for Android library project
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.android</groupId>
<artifactId>my-android-library</artifactId>
<version>0.1</version>
<packaging>apklib</packaging>
<name>my-android-library</name>
@yoshiki
yoshiki / pom.xml
Created October 13, 2011 02:27
Maven pom.xml for Android project
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.android</groupId>
<artifactId>my-android-app</artifactId>
<version>0.1</version>
<packaging>apk</packaging>