Skip to content

Instantly share code, notes, and snippets.

import UIKit
//"USA", return true
//"Calvin", return true
//"compUter", return false
//"coding", return true
func isUppercase(character: Character) -> Bool {
String(character) == character.uppercased()
}
import UIKit
extension String {
func isAlphanumeric() -> Bool {
return self.rangeOfCharacter(from: CharacterSet.alphanumerics.inverted) == nil && self != ""
}
func isAlphanumeric(ignoreDiacritics: Bool = false) -> Bool {
if ignoreDiacritics { return self.range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil && self != "" }
else { return self.isAlphanumeric() }
import Foundation
struct ProjectUser: Codable {
var id: Int
enum CodingKeys: String, CodingKey {
case id = "userId"
}
}
@tmm
tmm / hooks.js
Last active July 29, 2019 17:17
various react hooks
import { useEffect, useRef } from 'react'
export function useMount(callback) {
useEffect(callback, [])
}
export function usePrevious(value) {
const ref = useRef()
useEffect(() => (ref.current = value))
return ref.current
@tmm
tmm / cert.sh
Last active October 21, 2021 15:58
# configuration for cloudflare
CLOUDFLARE_EMAIL="name@example.com"
CLOUDFLARE_API_KEY="sdfsafsdafadsdsaf"
DOMAIN="example.com"
# as root configure your cloudflare secrets
mkdir -p .secrets
cat <<CLOUDFLARE_CONFIG > .secrets/cloudflare.ini
dns_cloudflare_email="$CLOUDFLARE_EMAIL"
dns_cloudflare_api_key="$CLOUDFLARE_API_KEY"
@tmm
tmm / gdax.js
Last active February 11, 2021 08:44 — forked from timpetri/gdax.js
Use CryptoJS for `CB-ACCESS-SIGN` GDAX API header
import CryptoJS from 'crypto-js'
const GDAX_SECRET = 'PYPd1Hv4J6/7x...';
const getGdaxSignature = (endpoint, body = '') => {
const timestamp = Date.now() / 1000;
const body = JSON.stringify(body);
const message = timestamp + method + endpoint + body; // create prehash string by concatenating required parts
const key = CryptoJS.enc.Base64.parse(GDAX_SECRET); // Base64 decode the alphanumeric secret string
const signedMessage = CryptoJS.HmacSHA256(message, key); // use it as key for SHA 256 HMAC
mkvirtualenv -p /usr/local/bin/python3.5 <name of venv>
@tmm
tmm / keybase.md
Created March 31, 2016 12:45
keybase proof

Keybase proof

I hereby claim:

  • I am tmm on github.
  • I am meagher (https://keybase.io/meagher) on keybase.
  • I have a public key whose fingerprint is D55C 2C17 A325 D985 CC01 0746 FDF6 0FC5 7C9E B567

To claim this, I am signing this object:

@tmm
tmm / swap.swift
Last active December 17, 2017 21:20
swap numeric variables without a third
var a = 5
var b = 3
a += b
b = a - b
a = a - b
print("a: \(a)") // 3
print("b: \(b)") // 5
@tmm
tmm / DynamicTableViewCellHeight.swift
Last active August 29, 2015 14:14
Dynamic Table View Cell Height in iOS 8 and Swift (snippet from http://www.raywenderlich.com/87975/dynamic-table-view-cell-height-ios-8-swift)
// Option 1 - For portrait orientation only
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 160.0
}
// Option 2 - For both portrait and landscape orientations
override func viewDidLoad() {
super.viewDidLoad()