Skip to content

Instantly share code, notes, and snippets.

@hlung
hlung / Raspberry Pi + SSH via ethernet quick setup (Mac).md
Last active July 27, 2016 14:26
A quick setup checklist from downloading an image file for Raspberry Pi until getting SSH via ethernet cable working with login password bypass.

Raspberry Pi + SSH via ethernet quick setup (Mac)

  1. download RASPBIAN from http://www.raspberrypi.org/downloads/. Download with torrent. Direct download usually fails (without any warning in Chrome! File size will be differ if download fails in the middle but there's no size to check in the download website!).
  2. And it's a good idea to check SHA1 of the zip file first. (e.g. openssl sha1 2014-01-07-wheezy-raspbian.zip)
  3. format SD card as FAT-32
  4. run df -h, find disk location. e.g. /dev/disk2s4", add r and remove s4 "/dev/rdisk2
  5. write the image file into SD card with command sudo dd bs=1m if=2014-01-07-wheezy-raspbian.img of=/dev/rdisk2 https://www.andrewmunsell.com/blog/getting-started-raspberry-pi-install-raspbian
  6. plug in HDMI before turn on RPi or else display will not work. If forgot, do NOT pull the power to restart right away. Wait for some time (about 3 min) for RPi to finish setting up its keys and stuff. Otherwise you will
@hlung
hlung / TestFlight-upload.sh
Last active October 13, 2016 07:30
A bash script to build on top of Shenzhen (https://github.com/nomad/shenzhen). Use specified targets of an Xcode iOS project.xcworkspace file, then upload to TestFlight.
#!/bin/bash
# TestFlight-upload.sh
# https://gist.github.com/hlung/7818585
#
# By Thongchai Kolyutsakul @hlungx
# Version: v1.0.3 - 27 Oct 2014
#
# Requirement: Shenzhen (https://github.com/nomad/shenzhen)
#
@hlung
hlung / MapValueExample.swift
Last active May 29, 2017 08:36
A Swift 3 example of mapValue(), a map() variant that only converts value of dictionary receiver and returns as a new dictionary instead of array.
//
// MapValueExample.swift
// ViKi
//
// Created by Thongchai Kolyutsakul on 29/5/17.
//
//
import Foundation
import SwiftyJSON
@hlung
hlung / vimium-dvorak-keys.txt
Last active June 8, 2017 03:15
Dvorak - Vimium Custom key mappings.This *unmaps* all keys and only adds frequently used ones.
# ::: Dvorak - Vimium Custom key mappings :::
# NOTE: This *unmaps* all keys and only adds frequently used ones.
# It mainly uses left hand keys so you don't have to let go of the mouse.
# How to use: open Vimium option screen, put this in "Custom key mappings" section.
 
unmapAll
 
# Link
map u LinkHints.activateMode
map U LinkHints.activateModeToOpenInNewTab
@hlung
hlung / CocoaAsyncSocket startTLS_without_cert.m
Last active August 22, 2017 21:38
CocoaAsyncSocket (https://github.com/robbiehanson/CocoaAsyncSocket) code for where/how to run -startTLS: method. We are connecting to server with self-signed certificate and don't include the certificate (public key .pem) in the client.
#pragma mark - GCDAsyncSocketDelegate
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port {
[self secureSocket:sock];
}
// We are connecting to server with self-signed certificate and don't include the certificate
// (public key .pem) in the client. So we skip all the cert checking. To actually check, see
// http://stackoverflow.com/questions/9874932/ssl-identity-certificate-to-run-an-https-server-on-ios
- (void)secureSocket:(GCDAsyncSocket *)sock {
// It has been changed in CocoaAsyncSocket v7.4, some old option keys are now unavailable and will throw exception.
// Use GCDAsyncSocketManuallyEvaluateTrust and evaluate in -socket:didReceiveTrust: delegate instead.

haha

  • 123
  • 456
@hlung
hlung / UIRefreshControl+beginRefreshing.h
Last active October 10, 2018 09:31
A UIRefreshControl beginRefreshing method that actually works
//
// UIRefreshControl+beginRefreshing.h
// Kibo
//
// Created by Hlung on 3/6/15.
// MIT License
//
#import <UIKit/UIKit.h>
@hlung
hlung / Pokemon.kt
Created April 29, 2019 09:24
Pokemon model classes in Kotlin
package com.raywenderlich.pokelist
import kotlinx.serialization.Serializable
@Serializable
data class Pokemon(
val name: String,
val url: String
)
@Serializable
@hlung
hlung / PokeApi.kt
Last active April 29, 2019 09:26
Pokemon API client in Kotlin
package com.raywenderlich.pokelist
import com.raywenderlich.pokelist.shared.ApplicationDispatcher
import com.raywenderlich.pokelist.shared.Image
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
@hlung
hlung / PokeListViewController.swift
Last active April 29, 2019 10:34
A UIViewController invoking PokeApi
import UIKit
import app
class PokeListViewController: UIViewController {
@IBOutlet var pokemonSprite: UIImageView!
@IBOutlet var pokemonInfo: UILabel!
@IBOutlet var pokeListTableView: UITableView!
internal var pokeList: [PokemonEntry] = []
internal var api = PokeApi()