Skip to content

Instantly share code, notes, and snippets.

View tomohisa's full-sized avatar

Tomohisa Takaoka tomohisa

View GitHub Profile
@tomohisa
tomohisa / GeneralTypeExtension.cs
Created September 26, 2023 04:46
Create Default Instance from Type
public static class GeneralTypeExtensions
{
public static dynamic CreateDefaultInstance(this Type type)
{
if (type == typeof(string))
{
return "";
}
if (type == typeof(char[]))
{
@tomohisa
tomohisa / User.cs
Created September 20, 2023 07:22
Interface property serialization / deserialization using JsonDerivedType
[JsonDerivedType(typeof(UnverifiedEmail), nameof(UnverifiedEmail))]
[JsonDerivedType(typeof(VerifiedEmail), nameof(VerifiedEmail))]
public interface IUserEmail;
public record UnverifiedEmail(string Value) : IUserEmail;
public record VerifiedEmail(string Value) : IUserEmail;
public record User(string Name, IUserEmail Email);
public class UserEmailTest
{
private readonly ITestOutputHelper _testOutputHelper;
@tomohisa
tomohisa / gist:2897676
Created June 8, 2012 19:20
Add and Remove ChildViewController
// add child view
UIViewController* controller = [self.storyboard instantiateViewControllerWithIdentifier:@"test"];
[self addChildViewController:controller];
controller.view.frame = CGRectMake(0, 44, 320, 320);
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
// remove child view
UIViewController *vc = [self.childViewControllers lastObject];
[vc.view removeFromSuperview];
@tomohisa
tomohisa / main.swift
Created May 24, 2016 14:55
code for SimpleMySQLClassGenerator
// Change below parameters to match your Environment
struct Constants: ConnectionOption {
var host: String = "127.0.0.1"
var port: Int = 3306
var user: String = "root"
var password: String = "CHANGE_TO_YOUR_PASSWORD"
var database: String = "CHANGE_TO_YOUR_PASSWORD"
var encoding: MySQL.Connection.Encoding = .UTF8MB4
var timeZone: MySQL.Connection.TimeZone = MySQL.Connection.TimeZone(GMTOffset: 60 * 60 * 9) // JST
@tomohisa
tomohisa / Question.md
Last active May 1, 2016 11:17
Question about ZEWO 0.5 HTTPS Client

HTTPSClient with Zewo 0.5 bad connection.

I am testing my Zewo 0.3 Project with Zewo 0.5

OSX El Capitan. Using bash, each snapshot installed

Using 0.3 with DEVELOPMENT-SNAPSHOT-2016-02-08-a

Using 0.5 with DEVELOPMENT-SNAPSHOT-2016-04-12-a

Both make it build and run

NSMutableAttributedString * mutable = [[NSMutableAttributedString alloc] init];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:self.user.name attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:12*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@" " attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:6*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"(@" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:self.user.screenName attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@")\t" attributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:11*TOVConstSizeRate]}]];
[mutable appendAt
-(BOOL)isFirstResponderRecursive{
if (self.isFirstResponder) {
return YES;
}
for (UIView * sub in self.subviews) {
if ([sub isFirstResponderRecursive]) {
return YES;
}
}
return NO;
@tomohisa
tomohisa / SpeechReading.m
Created November 26, 2013 16:25
short sample for AVSpeechSynthesizer voice reading feature for iOS 7
// 読み上げオブジェクト
AVSpeechSynthesizer * synthesizer = [[AVSpeechSynthesizer alloc] init];
// 読み上げる内容
AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc] initWithString:NSLocalizedString(@"Welcome to Tweet Overview ", nil)];
// 読み上げる言語の設定
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"ja-JP"];
utterance.pitchMultiplier = 1.0;
// 読み上げる
[synthesizer speakUtterance:utterance];
@interface ALAssetsLibrary (JTCCommon)
-(ALAsset*) getSyncAssetFromURL:(NSURL*)url;
-(UIImage*) getSyncFullScreenImageFromURL:(NSURL*)url;
-(UIImage*) getSyncFullResolutionImageFromURL:(NSURL*)url;
-(UIImage*) getSyncThumbnailImageFromURL:(NSURL*)url;
-(UIImage*) getSyncAspectThumbnailImageFromURL:(NSURL*)url;
@end