Skip to content

Instantly share code, notes, and snippets.

@ooharak
ooharak / macro.rb
Created December 7, 2012 05:35
window arrangement (win32+Ruby1.8.x)
#!/usr/bin/ruby
require 'Win32API'
require 'win32ole'
class Win32API
class Rect
def initialize(left,top,right,bottom)
@left = left
@ooharak
ooharak / menu.bas
Created December 7, 2012 07:28
An Excel VBA module snippet that allows macro menu import/export
' menu.bas - An Excel VBA module snippet that allows macro menu import/export
' Copyright 2012 (C) ooharak. All Rights Reserved.
' Note that currently you have to add a reference to MS Forms 2.0 type library
'
Option Explicit
Sub OpenBookLocation()
Call Shell("explorer """ & ActiveWorkbook.Path & """", vbNormalFocus)
End Sub
Private Function InitReferences() As Variant
@ooharak
ooharak / methodchain.rb
Created December 7, 2012 07:42
method chain feature for a Java object in JRuby
#method chain feature for a Java object in JRuby
class MethodChain
def initialize(underlying)
@underlying = underlying
end
def method_missing(name, *args, &block)
@underlying.send(name, *args, &block)
return self
end
@ooharak
ooharak / roman.hs
Created December 10, 2012 04:58
Roman numeric converter in Haskell
module Roman
where
roman' n (one:five:ten:[]) | n == 0 = []
| n == 4 = [one, five]
| n == 5 = [five]
| n == 9 = [one, ten]
| n > 5 = five : (roman' (n-5) (one:five:ten:[]) )
| otherwise = (roman' (n-1) (one:five:ten:[]) ) ++ [one]
@ooharak
ooharak / sort.hs
Created December 10, 2012 04:59
An incomplete snippet of Haskell study
module Sort
where
import IO
cat = bracket
(openFile "a.txt" ReadMode)
hClose
(\h -> docatloop h)
where docatloop h = do
@ooharak
ooharak / macro.rb
Created December 11, 2012 04:58
window arrangement (win32+Ruby1.9.x)
#!/usr/bin/ruby
require 'Win32API'
require 'win32ole'
class Win32API
class Rect
def initialize(left,top,right,bottom)
@left = left
@ooharak
ooharak / conn.c
Created December 11, 2012 06:39
An attempt to establish a TCP/IP connection to a host (C socket)
/* written by ooharak 2012. */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ip.h>
@ooharak
ooharak / oremock.py
Created December 19, 2012 04:42
A python mock object factory
#
# written by ooharak 2012. https://github.com/ooharak
# Usage:
# # an example test target
# def target():
# import os
# os.putenv('DUMMY', os.getenv('PATH')+'#'+os.getenv('USER'))
#
# ...
#
@ooharak
ooharak / merge.sh
Created December 19, 2012 08:29
Merge entries to a line-oriented key-value configuration file
#!/bin/sh
##
## by ooharak 2012.
##
## _merge_entries target_file < merge_file
## update entries in target_file with merge_file.
function _merge_entries {
local file=$1
local entry
while read entry ; do
@ooharak
ooharak / triplet.hs
Last active December 12, 2015 00:28
module Triplet
where
import List
newtype Triplet = Triplet Int
deriving(Show,Read)
instance Eq Triplet where
Triplet i == Triplet j = i == j
instance Ord Triplet where
(Triplet i) `compare` (Triplet j)