Skip to content

Instantly share code, notes, and snippets.

@hhyyg
hhyyg / object.assign.ts
Last active February 13, 2019 09:18
Object.assign(), Spread_syntax, Index Signatures
interface Foo {
readonly bar: number;
readonly baz: number;
}
const fooArray: Foo[] = [
{ bar: 100, baz: 200 },
{ bar: 300, baz: 400 },
]
@hhyyg
hhyyg / destructuring.ts
Created February 12, 2019 03:12
destructuring.ts
interface ViewModel {
name: string,
nums: number[],
displayName: string,
}
interface Model {
name: string,
nums: number[]
@hhyyg
hhyyg / readonly.ts
Created February 2, 2019 06:57
TypeScript readonly
// Properties
interface Foo {
readonly bar: number;
readonly bas: number;
}
const foo: Foo = { bar: 1, bas: 2 };
foo.bar = 11; // Error: [ts] Cannot assign to 'name' because it is a read-only property. [2540]
@hhyyg
hhyyg / readonly.ts
Created February 2, 2019 06:57
TypeScript readonly
// Properties
interface Foo {
readonly bar: number;
readonly bas: number;
}
const foo: Foo = { bar: 1, bas: 2 };
foo.bar = 11; // Error: [ts] Cannot assign to 'name' because it is a read-only property. [2540]
@hhyyg
hhyyg / main.ts
Created November 27, 2018 00:04
TypeScript Immutable and Copy
interface Person {
readonly groupName;
readonly name;
}
const taro: Person = {
groupName: "flower",
name: "taro",
}
@hhyyg
hhyyg / Karabiner.json
Created October 9, 2018 02:24
Karabiner.json
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
@hhyyg
hhyyg / qrcode.swift
Created April 16, 2018 05:27
Generate QR Code for iOS
import CoreImage
import UIKit
static func generateQRCode(url: String) -> UIImage? {
let data = url.data(using: .utf8)!
let params: [String: Any] = [
"inputMessage": data,
"inputCorrectionLevel": "L"
]
@hhyyg
hhyyg / code.swift
Last active November 17, 2020 09:16
How to access current firebase user from iOS App Extension.
import Foundation
import KeychainAccess //https://github.com/kishikawakatsumi/KeychainAccess
import Firebase
//Requires shared Keychain with the same group name
class ApplicationBuilder {
enum Target {
case app
@hhyyg
hhyyg / google_script.js
Last active December 17, 2017 07:07
IFTTTで行が挿入されたときに、最後の行の一列目の日付の文字列を、日付に変換する
var SPREADSHEET_ID = '****';
function onChange() {
var sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName('logs');
var currentRow = sheet.getLastRow();
if (currentRow<1) {
return;
}
var dateText = sheet.getRange(currentRow, 1).getValue();
if (typeof dateText != "string") {
@hhyyg
hhyyg / Book-AutoLayout.md
Last active December 12, 2017 07:02
本のメモ:よくわかるAuto Layout https://www.amazon.co.jp/dp/B01HG97S7K?tag=aokj24gaw-22

AutoLayout

外接矩形

  • デバッグ中に外接矩形を表示するオプション設定ができる 

Leading: 先頭 Trailing: 末尾 Baseline(LastBaseline), FirstBaseline Multiplier: 制約の係数