Skip to content

Instantly share code, notes, and snippets.

View standinga's full-sized avatar

standinga

View GitHub Profile
@standinga
standinga / CustomView.swift
Last active May 30, 2019 22:33
CustomView for medium post about UICollectionView inside UIView
import UIKit
@IBDesignable
class CustomView: UIView {
@IBOutlet var contentView: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
@standinga
standinga / CustomView.swift
Created May 30, 2019 22:57
CustomView.swift for medium post about UICollectionView inside UIView
private func initCollectionView() {
let nib = UINib(nibName: "CustomCell", bundle: nil)
collectionView.register(nib, forCellWithReuseIdentifier: "CustomCell")
collectionView.dataSource = self
}
@standinga
standinga / CustomView.swift
Created May 30, 2019 23:00
CustomView.swift for medium post about UICollectionView inside UIView
import UIKit
@IBDesignable
class CustomView: UIView {
@IBOutlet var contentView: UIView!
@IBOutlet weak var collectionView: UICollectionView!
override init(frame: CGRect) {
super.init(frame: frame)
@standinga
standinga / docker-compose.yml
Created June 17, 2019 23:59
docker-compose for medium post about moving existing wordpress into docker containers
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- ./wordpress.sql:/docker-entrypoint-initdb.d/init.sql # prepopulate database
- db_data:/var/lib/mysql # persist database data inside docker storage
restart: always
env_file:
@standinga
standinga / .env
Last active June 18, 2019 00:47
example .env file for medium post about moving wordpress into docker containers
MYSQL_ROOT_PASSWORD=somerootpassword
MYSQL_DATABASE=wordpress
MYSQL_USER=wordpress
MYSQL_PASSWORD=wordpress
@standinga
standinga / nginxserver
Created June 18, 2019 15:08
Nginx server block for medium post about moving wordpress into docker containers
server {
server_name nasulawesi.me www.nasulawesi.me;
location /pma/ {
proxy_pass http://localhost:8080/;
}
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host; #necessary for wordpress
@standinga
standinga / fetchData.swift
Last active July 9, 2019 22:08
function parsing into to string after defined delay time
func fetchData(_ data: Int, delay: Double, completionHandler: @escaping (String)->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
completionHandler("\(data)")
}
}
var text = ""
for i in 0..<20 {
fetchData(i, delay: Double.random(in: 0...0.2)) {
text += "\($0) - "
@standinga
standinga / main.swift
Created July 9, 2019 22:13
example for adding synchronization
let group = DispatchGroup()
var text = ""
for i in 0..<20 {
group.enter()
fetchData(i, delay: Double.random(in: 0...0.2)) {
text += "\($0) - "
group.leave()
}
}
group.notify(queue: DispatchQueue.main) {
@standinga
standinga / main.swift
Last active August 17, 2019 13:30
Final solution for medium post about DispatchGroup and DispatchSemaphore synchronization
import Foundation
func fetchData(_ data: Int, delay: Double, completionHandler: @escaping (String)->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
completionHandler("\(data)")
}
}
DispatchQueue.global().async {
let semaphore = DispatchSemaphore(value: 0)
@standinga
standinga / main.swift
Created August 17, 2019 13:37
fetchData function for medium blog post about DispatchGroup and DispatchSemaphore, https://link.medium.com/zJMQPUHaeZ
func fetchData(_ data: Int, delay: Double, completionHandler: @escaping (String)->()) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
completionHandler("\(data)")
}
}