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 / 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

@tomohisa
tomohisa / App.pch
Created January 20, 2015 14:29
Disable NSLog for keyboard extension
#ifdef DEBUG
//# define LOG(...) NSLog(@"%@", __VA_ARGS__)
//# define LOG_METHOD NSLog(@"%s", __func__)
//# define LOG_FORMAT(...) NSLog(__VA_ARGS__)
# define LOG(...) ;
# define LOG_METHOD ;
# define LOG_FORMAT(...) ;
#else
# define LOG(...) ;
@tomohisa
tomohisa / SetKeyboardHeight.m
Created December 30, 2014 14:12
Setting Keyboard Hight same even in Enlarged App
- (void)viewDidLoad {
[super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
if (self.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
self.portraitHeightRate = [UIScreen mainScreen].bounds.size.width * .4 / [UIScreen mainScreen].bounds.size.height;
}else{
if (([UIScreen mainScreen].bounds.size.width + [UIScreen mainScreen].bounds.size.height)>1100) {
self.portraitHeightRate = [UIScreen mainScreen].bounds.size.width * .6 / [UIScreen mainScreen].bounds.size.height;
} else if (([UIScreen mainScreen].bounds.size.width + [UIScreen mainScreen].bounds.size.height)>950) {
self.portraitHeightRate = [UIScreen mainScreen].bounds.size.width * .75 / [UIScreen mainScreen].bounds.size.height;
@tomohisa
tomohisa / UIViewController+JTCAddition.h
Created July 30, 2014 10:07
Storyboard by viewController factory method
#import <UIKit/UIKit.h>
@interface UIViewController (JTCAddition)
+(instancetype) viewControllerFromSameNameStoryboard;
+(UINavigationController*) viewControllerFromSameNameStoryboardInNavigationController;
@end
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;