Skip to content

Instantly share code, notes, and snippets.

View whoyawn's full-sized avatar

Huyanh Hoang whoyawn

  • New York
View GitHub Profile
import Foundation
class ThreadSafeArray<T: Equatable> {
private var queue = DispatchQueue(label: "com.threadsafe.array", attributes: .concurrent)
private var array: [T] = []
var count: Int {
var result = 0
queue.sync {
result = array.count
@whoyawn
whoyawn / PasswordGenerator.swift
Created November 9, 2021 17:58
Generate random passwords with OptionsSet
/**
Generate random String of given size in Swift
Given a size as n, generate a random alphanumeric String of this size.
// elements of Swift CharacterSet are Unicode.Scalar and we cannot view the members so we cannot use CharacterSet.
*/
struct CharSet: OptionSet {
@whoyawn
whoyawn / user-defaults-playground.swift
Created April 24, 2019 17:17
UserDefaults storage and the domains associated with them
import Foundation
print(UserDefaults.argumentDomain) // NSArgumentDomain
print(UserDefaults.globalDomain) // NSGlobalDomain
print(UserDefaults.registrationDomain) // NSRegistrationDomain
let defaults = UserDefaults.standard
defaults.set("This is a test", forKey: "name")
let readString = defaults.string(forKey: "name")
print(readString!)

Keybase proof

I hereby claim:

  • I am whoyawn on github.
  • I am huyanhh (https://keybase.io/huyanhh) on keybase.
  • I have a public key ASBD3FnLk98TIKWt99QfQ4GibPI0QUdiNjhNgq5IZpBMDgo

To claim this, I am signing this object:

@whoyawn
whoyawn / settings.js
Created July 15, 2018 03:58
VSCode User Settings
{
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "One Dark Pro",
"editor.tabSize": 2,
"editor.fontFamily": "SF Mono ,Menlo, Monaco, 'Courier New', monospace",
"editor.scrollBeyondLastLine": false,
}
### Keybase proof
I hereby claim:
* I am huyanhh on github.
* I am huyanhh (https://keybase.io/huyanhh) on keybase.
* I have a public key ASBL3UYsFyEclHM_1e6ClOj0Fv8WwmwAFrNyPa_jZ5zHWQo
To claim this, I am signing this object:
@whoyawn
whoyawn / PageDetail.js
Created May 13, 2017 04:40
Flatlist as view pager bug when trying to specify getItemLayout in props for use case, "scrolling to specific item on load"
/**
* Created by huyanh on 2017. 3. 22..
*/
import React, { Component } from 'react';
import { Dimensions, FlatList, Platform, View, Text, StyleSheet, TouchableOpacity } from 'react-native';
const LOREM_IPSUM = 'Lorem ipsum dolor sit amet, ius ad pertinax oportere accommodare, an vix \
civibus corrumpit referrentur. Te nam case ludus inciderint, te mea facilisi adipiscing. Sea id \
@whoyawn
whoyawn / app.js
Created March 15, 2017 18:30
practice with nested listviews
/**
* Created by huyanh on 2017. 3. 14..
*/
import React, { Component } from 'react';
import {
AsyncStorage,
ListView,
Text,
View,
} from 'react-native';