Skip to content

Instantly share code, notes, and snippets.

View ykst's full-sized avatar

YUKISHITA Yohsuke ykst

  • Mount Fuji, Japan
View GitHub Profile
@ykst
ykst / LSTree.hs
Created June 23, 2012 11:14
lstree implementation by Haskell
module Main where
import Directory (getDirectoryContents)
import Data.Tree (drawTree, unfoldTreeM)
import System.Environment (getArgs)
import Control.Applicative ((<$>), (<*>), pure)
import System.Posix.Files (isSymbolicLink, isDirectory,
readSymbolicLink,getSymbolicLinkStatus)
import System.FilePath.Posix ((</>), takeFileName)
main = getArgs >>= \args -> case args of
@ykst
ykst / Sudoku.hs
Created June 23, 2012 11:14
yet another sudoku solver
module Main where
import List (unfoldr, transpose, sort, (\\))
import System.Environment (getArgs)
import Control.Monad (foldM,msum)
type Nums = [Int]
solveProblems :: FilePath -> IO ()
solveFile :: FilePath -> IO ()
solveStr :: String -> String
test :: [[Nums]] -> Maybe [[Nums]]
@ykst
ykst / build.xml
Created October 9, 2012 18:44
Ant copy task (with PHP syntax checking)
<project name="Build Test" default="all" basedir="." >
<target name="all" depends="deploy"/>
<property name="tgtdir" value="/tmp"/>
<!-- パーミッションを気にする場合はcpを使うのが楽そう。
--parentがサポートされてない場合はcopyタスクとchownで頑張らないとかも
<target name="deploy_apps" >
<apply executable="cp" dest="/tmp" parallel="false">
<arg value="--parent"/>
<srcfile/>
@ykst
ykst / sh_syntax.sh
Created October 9, 2012 18:53
sh syntax memorandom
#!/bin/sh
MY_NAME=$0;
BASE_NAME=${0##*/};
DIR_NAME=${0%/*};
DIRDIR_NAME=${0%/*/*};
DEF_NAME=${_HIDDEN_NAME:-default}
echo $BASE_NAME;
echo $DIR_NAME;
@ykst
ykst / table.lua
Created November 9, 2012 01:45
Lua table hack
local function protect_table(tbl)
return setmetatable ({}, {
__index = tbl,
__newindex = function (t, n, v)
error ("attempting to change constant " ..
tostring (n) .. " to " .. tostring (v), 2)
end
})
end
@ykst
ykst / event.lua
Created November 27, 2012 18:47
event machine for lua
EventMachine = {--[[static members]]}
function EventMachine:new()
local this = {
current_actor = nil,
receivers_list = {},
event_register = {}
}
local on_mt = {
@ykst
ykst / Toc.hs
Created November 4, 2013 02:10
Generate markdown TOC for [Qiita](http://qiita.com/)
module Main where
import System.Environment (getArgs)
main = getArgs >>= \(f:_) -> readFile f >>= putStrLn . fromString
fromString = unlines . reverse . tocStr . lines
tocStr input = tocStr' input (repeat 0) []
where
tocStr' [] _ rs = rs
@ykst
ykst / NSObject+SimpleArchiver.h
Created November 6, 2013 17:19
単純なオブジェクトを永続化するカテゴリ ref: http://qiita.com/ykst@github/items/c5dcc71efd22e799dc31
#import <Foundation/Foundation.h>
@interface NSObject(SimpleArchiver)
// example:
// (archive)
// [SomeClass simpleArchiveForKey:@"a_key"];
// (unarchive)
// SomeClass *a_obj = [SomeClass simpleUnarchiveForKey:@"a_key"];
- (BOOL)simpleArchiveForKey:(NSString *)key;
+ (id)simpleUnarchiveForKey:(NSString *)key;
@ykst
ykst / file0.txt
Created November 8, 2013 14:56
iOSで動作中のプロセスのメモリ使用量を調べる ref: http://qiita.com/ykst@github/items/a896b70815b6e76f7af0
#include <sys/proc_info.h>
#include <sys/sysctl.h>
#include <libproc.h>
void dump_process_memory_usage()
{
size_t size = 0;
// 全てのプロセスのPIDを取得
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
sysctl(mib, 4, NULL, &size, NULL, 0);
@ykst
ykst / BundleHelper.m
Created November 10, 2013 15:47
Bundle IDからアプリのアイコンを取得する ref: http://qiita.com/ykst@github/items/ffc09fee78483d04b571
@interface BundleHelper : NSObject
+ (void)retrieveIconURLForBundleID:(NSString *)bundle_id withHandler:(void (^)(NSURL *url))handler;
@end
@implementation BundleHelper
+ (void)retrieveIconURLForBundleID:(NSString *)bundle_id withHandler:(void (^)(NSURL *))handler
{
// カレントロケールからストアの国を推定
static NSString *country;
NSLocale *currentLocale = [NSLocale currentLocale];