Skip to content

Instantly share code, notes, and snippets.

View cesare's full-sized avatar

SAWADA Tadashi cesare

View GitHub Profile
#
# Nabeatsu
# returns "hoge" if given value is a multiple of 3, or contains '3' in it; otherwise just the value itself (in String).
#
# Restriction of coding:
# DO NOT use conditional branching syntax, such as "if", "unless", "case ... when".
#
module Nabeatsu
class << self
def say(n)
@cesare
cesare / gist:2703414
Created May 15, 2012 17:17
Sample bash script to build PJSIP library for iphone SDK
#!/bin/bash
srcdir="${HOME}/src/pjproject-2.0-rc"
cd ${srcdir}
(
cat <<END
#define PJ_CONFIG_IPHONE 1
#include <pj/config_site_sample.h>
import Data.List
intToRoman :: Int -> String
intToRoman = concat . reverse . (zipWith (\f d -> f d) fs) . split
where
split = unfoldr (\n -> if n > 0 then Just ((mod n 10), (div n 10)) else Nothing)
fs = map roman [('i', 'v', 'x'), ('x', 'l', 'c'), ('c', 'd', 'm'), ('m', '$', '#')]
roman (one, five, ten) n
| n >= 0 && n <= 3 = replicate n one
| n == 4 = [one, five]
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
class String
def &(other)
self.unpack("U*").zip(other.to_s.unpack("U*")).map{|pair| pair.first & pair.last }.pack("U*")
end
end
puts "生" & "死"
#!/usr/bin/env ruby
require 'open-uri'
require 'nokogiri'
require 'growl'
doc = Nokogiri::HTML(open("http://shop.github.com/products/octodex-sticker-pack"))
if doc.css('#puchase-form .sold-out').empty?
Growl.notify do |n|
n.message = 'Octodex Sticker Packs are back!'
#!/bin/bash
#
# Emacs 23.3 building procedure for MacOSX
# thanks to http://masutaka.net/chalow/2011-07-31-2.html
#
#
# settings
#
@cesare
cesare / mongod.conf
Created September 9, 2011 12:58
MacOSX launchd plist file to start MongoDB server
dbpath = /var/mongo/data
logpath = /var/mongo/logs/mongod.log
#! /usr/bin/perl -w
use Crypt::Rijndael;
use Digest::SHA;
my $cleartext = "Here is some data for the coding"; # 32 bytes
my $iv = 'a2xhcgAAAAAAAAAA';
my $hash_1 = Digest::SHA->new(256); # SHA256
$hash_1->add("Nixnogen");
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'base64'
require 'digest'
require 'openssl'
def encode(cryptkey, iv, cleardata)
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt
# -*- mode: ruby; coding: utf-8 -*-
#
# naive imitation #1 of NSNotificationCenter of Cocoa Framework
#
class NotificationCenter
def self.default
@instance ||= NotificationCenter.new