Skip to content

Instantly share code, notes, and snippets.

View standinga's full-sized avatar

standinga

View GitHub Profile
@standinga
standinga / main.swift
Last active August 17, 2019 14:17
fetchData function for medium blog post about DispatchGroup and DispatchSemaphore, https://link.medium.com/zJMQPUHaeZ
func combineAsyncCalls(completionHandler: @escaping (String)->()) {
var text = ""
fetchData(0, delay: 0.4) { text += $0 }
fetchData(1, delay: 0.2) { text += $0 }
completionHandler(text)
}
combineAsyncCalls() {
print($0)
@standinga
standinga / main.swift
Last active August 17, 2019 14:16
fetchData function for medium blog post about DispatchGroup and DispatchSemaphore, https://link.medium.com/zJMQPUHaeZ
func combineAsyncCallsWithDispatchGroup(completionHandler: @escaping (String)->()) {
let group = DispatchGroup()
var text = ""
group.enter()
fetchData(0, delay: 0.4) {
text += $0
group.leave()
}
group.enter()
fetchData(1, delay: 0.2) {
@standinga
standinga / main.swift
Last active August 17, 2019 14:17
fetchData function for medium blog post about DispatchGroup and DispatchSemaphore, https://link.medium.com/zJMQPUHaeZ
func combineAsyncCallsWithSemaphore(completionHandler: @escaping (String)->()) {
let semaphore = DispatchSemaphore(value: 0)
var text = ""
DispatchQueue.global().async {
fetchData(0, delay: 0.4) {
text += $0
semaphore.signal()
}
semaphore.wait() // wait for the first fetchData complete
@standinga
standinga / AudioUnitViewController.swift
Created September 26, 2019 02:31
updated AudioUnitViewController initializers for medium blog article about How To Create Audio Unit From Scratch
// this initializer is called by NSExtensionContextVendor beginRequestWithExtensionItems,
// without it Garage Band will not show the UI!
init() {
super.init(nibName: "AudioUnitViewController", bundle: Bundle(for: AudioUnitViewController.self))
}
override public init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: "AudioUnitViewController", bundle: Bundle(for: AudioUnitViewController.self))
}
@standinga
standinga / UIFont+Monospace.swift
Created September 28, 2019 22:46
UIFont extension for monospaced font.
import UIKit
extension UIFont {
static func monospacedFont(at size: CGFloat) -> UIFont{
let bodyFontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: UIFont.TextStyle.body)
let bodyMonospacedNumbersFontDescriptor = bodyFontDescriptor.addingAttributes(
[
UIFontDescriptor.AttributeName.featureSettings: [
@standinga
standinga / firebase.js
Last active November 20, 2019 03:18
firebase.js plugin for the medium post about configuring google-sign in with vue, nuxt, firebase
import firebase from 'firebase'
// copy the config from the console https://console.firebase.google.com/u/0/project/sign-11111/settings/general/
var firebaseConfig = {
apiKey: "AI1111111111111111111111111111",
authDomain: "sign-1111111.firebaseapp.com",
databaseURL: "https://sign-11111.firebaseio.com",
projectId: "sign-11111",
storageBucket: "sign-11111.appspot.com",
messagingSenderId: "111111111111",
@standinga
standinga / index.vue
Last active November 20, 2019 03:02
cleaned up index.vue for the medium post about
<template>
<div class="container">
google-sign
</div>
</template>
<script>
export default {
created: async function() {
}
@standinga
standinga / index.vue
Created November 20, 2019 03:42
Updated index.vue for the medium blog posts
<template>
<div class="container">
<button @click="signInRedirect">Sign With Redirect</button>
<button @click="signInPopup">Sign With Pop Up</button>
<button @click="test">Test</button>
</div>
</template>
<script>
@standinga
standinga / rules.json
Created November 20, 2019 04:28
update firebase rules for medium post about authentication with google sign in
{
"rules": {
".read": "auth.uid != null && auth.token.email.contains('borama')",
".write": "auth.uid != null && auth.token.email.contains('borama')"
}
}
@standinga
standinga / index.js
Last active November 20, 2019 04:31
updated signInPopu function for medium post about authenticating with google sign in
signInPopup: async function() {
var provider = new this.$firebase.auth.GoogleAuthProvider()
const result = await this.$firebase.auth().signInWithPopup(provider)
var user = result.user
console.log(user)
},