Skip to content

Instantly share code, notes, and snippets.

@hoshi-takanori
hoshi-takanori / MyTextView.h
Last active February 11, 2020 23:07
UITextView subclass to replace range with attributed text, with undo/redo support. (iOS 7 only)
#import <UIKit/UIKit.h>
@interface MyTextView : UITextView
- (void)replaceSelectionWithAttributedText:(NSAttributedString *)text;
- (void)replaceRange:(NSRange)range withAttributedText:(NSAttributedString *)text;
@end
@hoshi-takanori
hoshi-takanori / NSUndoManager+Logging.m
Created December 31, 2013 06:02
Logging category of NSUndoManager class.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface NSUndoManager (Logging)
@end
@implementation NSUndoManager (Logging)
+ (void)load
@hoshi-takanori
hoshi-takanori / Makefile
Last active October 3, 2019 18:17
Testing Objective-C class by XCTest with plain old Makefile in command line.
CLASS_NAME = MyObject
OBJS = main.o $(CLASS_NAME).o $(CLASS_NAME)Tests.o
PROGRAM = a.out
CFLAGS = -Wall -F$(FWPATH)
LIBS = -F$(FWPATH) -framework XCTest -framework Foundation
FWPATH = /Applications/Xcode.app/Contents/Developer/Library/Frameworks
XCTEST = /Applications/Xcode.app/Contents/Developer/usr/bin/xctest
@hoshi-takanori
hoshi-takanori / MyTest.java
Created April 1, 2014 20:36
Java unit test with JUnit vs groovy's power assert.
import junit.framework.TestCase;
public class MyTest extends TestCase {
private int a, b;
@Override
public void setUp() {
a = 1;
b = 2;
}
@hoshi-takanori
hoshi-takanori / sync.pl
Created April 3, 2014 05:52
Sync files in local and remote directories via SFTP by perl.
#!/usr/bin/perl
use strict;
use Fcntl ':mode';
use File::stat 'stat';
use Net::SFTP::Foreign;
my $HOST = 'user@example.com';
my $PASS = '********';
my $MORE = [ -o => 'StrictHostKeyChecking no' ];
@hoshi-takanori
hoshi-takanori / webprog.txt
Last active August 29, 2015 14:01
Webプログラミング入門の講義予定。
Webプログラミング入門
1. ネットワークプログラミングの基礎
講義
- ネットワークの論理構成
- ホスト名とIPアドレス
- TCP/UDPとポート番号
- プロトコル、ステートフルとステートレス
演習
簡単なチャットプログラム
@hoshi-takanori
hoshi-takanori / Server.java
Created May 29, 2014 11:49
ちょーかんたんなサーバー。
import java.io.*;
import java.net.*;
/**
* ちょーかんたんなサーバー。
*/
public class Server {
/**
* ポート番号。
*/
@hoshi-takanori
hoshi-takanori / MyMemoryStore.js
Last active August 29, 2015 14:03
Create my own session store for Express 4.
module.exports = function (session) {
var Store = session.Store;
function MyMemoryStore(options) {
Store.call(this, options || {});
this.debug = options && options.debug;
this.sessions = {};
}
MyMemoryStore.prototype.__proto__ = Store.prototype;
@hoshi-takanori
hoshi-takanori / app.js
Last active December 2, 2021 10:25
Invoke CGI from Express.js.
var express = require('express');
var cgi = require('./cgi');
app = express();
var script = __dirname + '/hello.cgi';
app.get('/', cgi(script, function (req, options) {
options.env.USERNAME = 'Mr. User';
}));
app.use(function (err, req, res, next) {
@hoshi-takanori
hoshi-takanori / custom-file-server.go
Last active August 29, 2015 14:21
Custom http.FileServer to overwrite Content-Type header.
package main
import (
"net/http"
"strings"
)
var CustomTypeMap = map[string]string{
"text/x-java-source": "text/plain",
}