Skip to content

Instantly share code, notes, and snippets.

View sarunw's full-sized avatar
🍎
iOS, Swift, SwiftUI

Sarun Wongpatcharapakorn sarunw

🍎
iOS, Swift, SwiftUI
View GitHub Profile
<div class="social">
<span class="twitter">
<a href="http://twitter.com/share" class="twitter-share-button" data-url="[your-url-here]">Tweet</a>
</span>
<span class="google">
<g:plusone size="medium" href="[your-url-here]"></g:plusone>
</span>
<span class="Facebook">
<iframe src="https://www.facebook.com/plugins/like.php?href=[your-url-here]&amp;show_faces=false&amp;layout=button_count" scrolling="no" frameborder="0" style="height: 21px; width: 100px" allowTransparency="true"></iframe>
</span>
@sarunw
sarunw / gist:52aa0e843f912b5b672f
Created January 31, 2015 16:39
Copy all screenshot from current directory to all subdirectories in specific path
for d in [path_to_screenshot_images]/*; do cp * "$d"; done
@sarunw
sarunw / gist:9ba2593d0cb21d553005
Created January 31, 2015 19:12
Auto increment build number of xcode based on git commit.
echo "CONFIG $CONFIGURATION"
if [ "$CONFIGURATION" != "Release" ]; then
exit 0
fi
BUILD_NUMBER=$(git rev-list HEAD --count)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "$INFOPLIST_FILE"
# For debugging:
echo "BUILD NUMBER: $BUILD_NUMBER"
@sarunw
sarunw / Podfile.ruby
Last active October 23, 2015 11:30 — forked from orta/Podfile.ruby
make frameworks the same as your bundle id
post_install do |installer|
app_plist = "Emergence/Info.plist"
plist_buddy = "/usr/libexec/PlistBuddy"
version = `#{plist_buddy} -c "Print CFBundleShortVersionString" #{app_plist}`
puts "Updating CocoaPods' version numbers to #{version}"
installer.pods_project.targets.each do |target|
`#{plist_buddy} -c "Set CFBundleShortVersionString #{version}" "Pods/Target Support Files/#{target}/Info.plist"`
end
end
@sarunw
sarunw / ruby_readline_issue.md
Created April 21, 2018 06:19 — forked from soultech67/ruby_readline_issue.md
ruby bundler: Sorry, you can't use byebug without Readline

Preamble

On OS/X Sierra, after recently running a brew update I started receiving the error message Sorry, you can't use byebug without Readline when trying to run some rake tasks in my ruby project folder. I observed this in projects and gems that include byebug or pry in their Gemfile or gem.spec. I've found in my googling that many begin encountering this error message after running a brew update but there are other triggering conditions as well.

>> rake aws:show_config
WARN: Unresolved specs during Gem::Specification.reset:
      mime-types (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
 Sorry, you can't use byebug without Readline. To solve this, you need to
@sarunw
sarunw / rails-deploy-to-digitalocean.md
Created September 7, 2018 08:43 — forked from kylefdoherty/rails-deploy-to-digitalocean.md
Notes for myself on How to Deploy a Rails App to DigitalOcean with Ubuntu 14.04, Phusion Passenger & Nginx, Postgres, and Capistrano

How to Deploy a Rails App to DigitalOcean with Ubuntu 14.04, Phusion Passenger & Nginx, Postgres, and Capistrano

1. Setup DigitalOcean Droplet

  • Choose Server Image

choose server image

  • Choose Size (if this is a hobby app you can probably get away with the smallest)

choose server size

@sarunw
sarunw / money.swift
Created October 7, 2018 15:08
Float and Double error
var float: Float = 0.01
var floatSum: Float = 0
for i in 0..<100 {
floatSum += float
}
floatSum
floatSum == 1
var double: Double = 0.01
struct Base64ImageWrapper: Codable {
let image: UIImage
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let base64String = try container.decode(String.self)
let components = base64String.split(separator: ",")
if components.count != 2 {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Wrong data format")
}
enum ImageEncodingQuality: CGFloat {
case png = 0
case jpegLow = 0.2
case jpegMid = 0.5
case jpegHigh = 0.75
}
extension KeyedEncodingContainer {
mutating func encode(_ value: UIImage,
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
let object = fetchedResultsController.object(at: indexPath)
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
controller.detailItem = object
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
}
}