Skip to content

Instantly share code, notes, and snippets.

@noqisofon
noqisofon / which.rb
Created December 28, 2010 07:19
Ruby で書かれた which コマンド(Windows 用)。
#!c:/bin/ruby/bin/ruby
# encoding: shift_jis
# いわゆる「パスの通った」ディレクトリリスト。
PATH = ENV["PATH"].split( /;/ ).collect { |path| path.gsub(/\\/, "/") }
# Windows で実行可能な拡張子。
EXECUTABLE_EXTENSION = ENV["PATHEXT"].split( /;/ ).collect { |ext| ext.gsub(/\./, "").downcase }
def search_command(pattern)
PATH.each do |path|
@noqisofon
noqisofon / gist:758217
Created December 29, 2010 05:30
値を返す if 式の代替?
#!c:/bin/ruby/bin/ruby
# -*- encoding: cp932 -*-
=begin
><div>
<p>ということで、こういうことをしたかったんだけど:</p>
</div><
>|ruby|
puts if ((0..12).cover? Time.now.hour then "Hello, World!" else "Good evening, World!"
||<
@noqisofon
noqisofon / man2pdf.rb
Created December 31, 2010 08:53
man ページを pdf で保存する感じ。
path = "/usr/bin"
tmpdir_path = File.expand_path( "~/var/ps" )
outdir_path = File.expand_path( "~/etc/manuals" )
Dir.entries(path).each do |filename|
next if File.directory? "#{path}/#{filename}"
puts "#{filename}"
Dir.mkdir tmpdir_path unless File.exists? tmpdir_path
@noqisofon
noqisofon / gist:766442
Created January 5, 2011 15:22
scheme で書いたピザ 10 回。
;; -*- coding: shift_jis -*-
(define (say-piza n)
(cond
((> n 0)
(display "ピザ")
(say-piza (- n 1)))))
(say-piza 10)
@noqisofon
noqisofon / AtomDotNetSample.cs
Created January 6, 2011 02:10
Atom.NET の Example の Writer 部分。
using System.IO;
using System.Net;
using System.Text;
using Atom;
using Atom.Core;
using Atom.Core.Collections;
using Atom.Utils;
@noqisofon
noqisofon / AtomWroteSample.cs
Created January 6, 2011 05:03
Atom っぽい XML を書きだす感じ。
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
namespace test.xmlwrote {
@noqisofon
noqisofon / Winsock.hxx
Created January 12, 2011 00:45
ローカル IP を取得する。
#ifndef Winsock_hxx
#define Winsock_hxx
#include <winsock2.h>
/**
*
*/
class Winsock
@noqisofon
noqisofon / getservbyname.cpp
Created January 12, 2011 06:40
http://d.hatena.ne.jp/spidy_spidy/20080423/1208878797 のソースを windows でもコンパイルできるように修正してみた。
#include <stdio.h>
#if defined(_WIN32)
# include <winsock2.h>
# pragma comment(lib, "ws2_32.lib")
#else
# include <netdb.h>
#endif /* defined(__WIN32__) */
// http://d.hatena.ne.jp/spidy_spidy/20080423/1208878797 より
int main(int argc, char* argv[])
@noqisofon
noqisofon / LinqExtractsIPAddressSample.cs
Created January 13, 2011 02:11
IPv4 なローカル IP アドレスを Linq で見つける。
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Text;
namespace demo.linq.ipaddr {
@noqisofon
noqisofon / zencoding.txt
Created January 13, 2011 06:29
zencoding な html スケルトン。
html xmlns=http://www.w3.org/1999/xhtml>(head>title+link rel=stylesheet type=text/css href=./style/screen.css+meta http-equiv=Content-Type content=text/html;charset=UTF-8+meta name=generator content=zencoding)+body.layout>(div.page>div.header+(div.content>h1+p)+div.footer)