Skip to content

Instantly share code, notes, and snippets.

View m1kah's full-sized avatar

Mika Hämäläinen m1kah

View GitHub Profile
@m1kah
m1kah / DurationInputField.swift
Created March 27, 2021 08:28
Partial SwiftUI field that allows input of hours and minutes
struct UIDurationField: UIViewRepresentable {
func makeUIView(context: Context) -> UITextField {
let coordinator = context.coordinator
let textField = PaddedTextField()
textField.delegate = coordinator
textField.backgroundColor = MyUIColor.textFieldBackground
textField.textAlignment = .center
textField.keyboardType = .numberPad
textField.placeholder = "00" + String(coordinator.separator) + "00"
cat settings.gradle | sed -n -e 's/rootProject\.name = '\''\(.*\)'\''/\1/p'
@m1kah
m1kah / .zhsrc
Created February 29, 2020 14:02
# zstyle : Instructs the shell on how to provide inline,
# contextual hints
# fpath : The git-completion.zsh is a function file,
# not designed to be sourced like the bash script.
# This command appends the ~/.zsh directory onto
# the shell’s function lookup list.
# autoload : Scan each path within the fpath variable for
# files starting with an underscore (_git , in our
# case) and loads the corresponding script as a
# function file
@m1kah
m1kah / uuidgen.awk
Last active September 8, 2019 17:00
Generate uuid values with awk
awk '("uuidgen" | getline uuid) > 0 {print $0, uuid} {close("uuidgen")}' output.json
@m1kah
m1kah / TableUtil.swift
Created August 25, 2019 07:30
iOS table select background color
static func makeSelectedBackgroundView() -> UIView {
let view = UIView()
view.backgroundColor = Color.selectedCell
return view
}
@m1kah
m1kah / add_code_initialization.awk
Created August 25, 2019 07:29
Gawk script for string transform
gawk -F '"' '{code=gensub(" ", "_", "g", $2); print $1 "\x22"$2"\x22,", "code: \x22" tolower(code) "\x22" $3}' activity_list.txt
:r !uuidgen|sed 's/.*/"uuid": "&",/'
guard let interval = calendar.dateInterval(of: .month, for: Date()) else { return }
@m1kah
m1kah / DateUtil.swift
Created July 10, 2017 04:52
Swift current week, start of year, week range in this year
import Foundation
class DateUtil {
private init() {
}
static func currentWeek() -> Int {
let calendar = NSCalendar.current
let dateComponent = calendar.component(Calendar.Component.weekOfYear, from: Date())
return dateComponent
#!/bin/sh
# usage: ./find-class.sh <path> <class name>
find "$1" -name "*.jar" -exec sh -c 'jar tf {} | grep -H --label {} '$2'' \;