Skip to content

Instantly share code, notes, and snippets.

@hoshi-takanori
hoshi-takanori / gob-example.go
Created May 27, 2015 08:30
How to use bytes.Buffer with gob encoder/decoder.
package main
import (
"bytes"
"encoding/gob"
"io"
)
type Data struct {
A int
@hoshi-takanori
hoshi-takanori / nolist.go
Last active February 24, 2024 18:56
http.FileServer with no directory listing.
// http://grokbase.com/p/gg/golang-nuts/12a9xcadca/go-nuts-disable-directory-listing-with-http-fileserver
package main
import (
"net/http"
"os"
)
type NoListFile struct {
@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 / 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 / ComposeEditModal,kt
Created March 8, 2021 12:56
CustomDialog with TextField in Jetpack Compose 1.0.0-beta01
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
@hoshi-takanori
hoshi-takanori / ComposeEditDialog.kt
Created March 7, 2021 22:00
AlertDialog with TextField doesn't work in Jetpack Compose 1.0.0-beta01
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.runtime.Composable
@hoshi-takanori
hoshi-takanori / MultiTouchView.java
Created December 3, 2016 03:46
Android Multi-Touch View.
package com.example.multitouch;
import android.content.Context;
import android.graphics.PointF;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import java.util.HashMap;
import java.util.Map;
@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
class Person {
let name: String
init(name: String) { self.name = name }
func printName() { print("name = \(name)") }
deinit { print("\(name) is being deinited") }
}
var p: Person? = Person(name: "Hoshi")
p?.printName() // name = Hoshi
@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