Skip to content

Instantly share code, notes, and snippets.

View yusuke024's full-sized avatar

Yusuke Onishi yusuke024

  • Google
  • Tokyo, Japan
View GitHub Profile
@yusuke024
yusuke024 / ImageMagickExamples.sh
Last active July 25, 2022 15:18
ImageMagick Examples
# Append image horizontally
magick image1.png image2.png +append -gravity center -undercolor clear out.png
# Add annotation
magick -font helvetica -gravity north -fill red -undercolor white -pointsize 24 -annotate +0+8 image.png "Text" out.png
# Put screenshots in bezel
magick -background none -gravity center screenshot.png -extent 1400x2700 bezel.png -composite out.png
# Generate Swift source files from a `.xcdatamodeld` file.
xcrun momc \
--action generate \
--swift-version 5.0 \
/path/to/MyModel.xcdatamodeld \
~/path/to/output/dir
@yusuke024
yusuke024 / main.swift
Created June 9, 2020 09:36
Convert NSLocalizedString code into a Localizable.strings entry
struct NSLocalizedString {
enum Bundle {
case main
}
var key: String
var value: String
var comment: String
init(_ key: String, tableName: Int?, bundle: Bundle?, value: String, comment: String) {
@yusuke024
yusuke024 / aina.swift
Last active March 3, 2020 07:19
A in A
#!/usr/bin/env swift
// swift aina.swift <n>
import Foundation
func p(_ n: Int) -> [String] {
if n == 0 { return ["A"] }
let p1 = [" A ", "A A", "AAA", "A A", "A A"]
@yusuke024
yusuke024 / simctl.sh
Last active March 11, 2020 04:53
Useful Xcode commands
iOS Simlator Commands
# Uninstall an app from simulator
xcrun simctl uninstall <device_id> <app_identifier>
# Example:
# xcrun simctl uninstall 0BFBAE3C-DD58-4DD7-8F24-E9D9674A4004 com.apple.App
# Screenshot
xcrun simctl io booted screenshot </path/to/save.png>
#!/usr/bin/env swift
CommandLine.arguments // Get command-line arguments in the form of Swift array
print(_:separator:terminator) // Print to stdout
while let line = readLine() { … } // Read from stdin line-by-line
@yusuke024
yusuke024 / c.md
Last active August 7, 2019 04:31
Compile

C++

g++ main.cpp

For C++11

g++ -std=c++11 main.cpp
import PlaygroundSupport
class Node: CustomStringConvertible {
var name = ""
var edges = [Edge]()
init(_ name: String) {
self.name = name
}
```swift
⭕️
observable1.flatMap { [weak self] ... in
print(self?.value)
return observable2.flatMap { ... in in
print(self?.value)
}
}
⭕️
extension NSAttributedString {
convenience init?(htmlString: String) {
guard let data = htmlString.data(using: .unicode) else { return nil }
let options: [NSMutableAttributedString.DocumentReadingOptionKey: Any] = [.documentType: NSAttributedString.DocumentType.html]
do {
try self.init(data: data, options: options, documentAttributes: nil)
} catch {
return nil
}
}