Skip to content

Instantly share code, notes, and snippets.

View lohenyumnam's full-sized avatar
👨‍💻
Working...

Lohen lohenyumnam

👨‍💻
Working...
View GitHub Profile
export const getThumbnail = (id, size = 300) =>
`https://drive.google.com/thumbnail?id=${id}&sz=${size}`;
export const getIcon = (mimeType) =>
`https://drive-thirdparty.googleusercontent.com/256/type/${mimeType}`;
export const getFile = (id) => `https://drive.google.com/uc?id=${id}`;
const downloadFile = (id) =>
@helenaford
helenaford / 1: App.js
Last active March 20, 2024 09:16
useNotificationService
import { useNotificationService } from './hooks';
function App() {
useNotificationService();
...
}
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@Azoy
Azoy / install-swift-ubuntu.md
Last active December 9, 2022 03:42
Guide on how to install Swift on Ubuntu

Install Swift on Ubuntu

Requirements

  1. Ubuntu 14.04, 16.04, or 16.10

Step 1 - Dependencies

  1. Open up terminal
  2. Install core deps: sudo apt-get install clang libicu-dev git

Step 1.1 - Ubuntu 14.04 Clang

@gyubokbaik
gyubokbaik / panGestureRecognizerHandler.txt
Created March 29, 2017 00:02
Blog - Dismiss ViewControllers Presented Modally Using Swipe Down
// define a variable to store initial touch position
var initialTouchPoint: CGPoint = CGPoint(x: 0,y: 0)
@IBAction func panGestureRecognizerHandler(_ sender: UIPanGestureRecognizer) {
let touchPoint = sender.location(in: self.view?.window)
if sender.state == UIGestureRecognizerState.began {
initialTouchPoint = touchPoint
} else if sender.state == UIGestureRecognizerState.changed {
if touchPoint.y - initialTouchPoint.y > 0 {
@gbitaudeau
gbitaudeau / Int+Extenstion.swift
Created March 3, 2017 09:44
iOS solution to convert large numbers to smaller format. See : http://stackoverflow.com/a/35504720/1661338
extension Int {
func formatUsingAbbrevation () -> String {
let numFormatter = NSNumberFormatter()
typealias Abbrevation = (threshold:Double, divisor:Double, suffix:String)
let abbreviations:[Abbrevation] = [(0, 1, ""),
(1000.0, 1000.0, "K"),
(100_000.0, 1_000_000.0, "M"),
(100_000_000.0, 1_000_000_000.0, "B")]
@toddhopkinson
toddhopkinson / BackgroundTransferSample.swift
Last active September 27, 2023 01:47
Upload Very Large Files In Background on iOS - Alamofire.upload multipart in background
// You have a very very large video file you need to upload to a server while your app is backgrounded.
// Solve by using URLSession background functionality. I will here use Alamofire to enable multipart upload.
class Networking {
static let sharedInstance = Networking()
public var sessionManager: Alamofire.SessionManager // most of your web service clients will call through sessionManager
public var backgroundSessionManager: Alamofire.SessionManager // your web services you intend to keep running when the system backgrounds your app will use this
private init() {
self.sessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.default)
self.backgroundSessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.background(withIdentifier: "com.lava.app.backgroundtransfer"))
@tzmartin
tzmartin / embedded-file-viewer.md
Last active April 15, 2024 06:30
Embedded File Viewer: Google Drive, OneDrive

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

@Thunderbird7
Thunderbird7 / AbbreviateNumber.swift
Last active December 27, 2018 15:54
[Swift] Abbreviate number class, such as number of 1500 convert to 1.5k
func abbreviateNumber(num: NSNumber) -> String {
// less than 1000, no abbreviation
if num < 1000 {
return "\(num)"
}
// less than 1 million, abbreviate to thousands
if num < 1000000 {
var n = Double(num);
n = Double( floor(n/100)/10 )
@calt
calt / Tabbar.Swift
Last active January 9, 2024 05:58
UITabBar with custom height in Swift, does not work for iOS 14 or later.
// Does not work on iOS 14.0 or later, keeping the gist just for reference.
extension UITabBar {
override open func sizeThatFits(size: CGSize) -> CGSize {
super.sizeThatFits(size)
var sizeThatFits = super.sizeThatFits(size)
sizeThatFits.height = 71
return sizeThatFits
}
}