Skip to content

Instantly share code, notes, and snippets.

View IhwanID's full-sized avatar

Ihwan IhwanID

View GitHub Profile
@IhwanID
IhwanID / main.swift
Last active February 1, 2024 13:00
Given a set of numbers, determine if there is a pair that equals a given sum.
//func hasPairWithSum(_ arr: [Int], _ sum: Int) -> Bool {
//
// for i in 0..<arr.count {
// for j in i + 1..<arr.count {
// if arr[i] + arr[j] == sum {
// return true
// }
// }
// }
// return false
@IhwanID
IhwanID / CocoaStandard.sdef
Created June 23, 2023 03:41
Apple Standard SDEF file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Standard Terminology">
<suite name="Standard Suite" code="????" description="Common classes and commands for all applications.">
<command name="open" code="aevtodoc" description="Open a document.">
<direct-parameter description="The file(s) to be opened.">
<type type="file"/>
@IhwanID
IhwanID / main.kt
Created August 27, 2019 12:28
Open Whatsapp Intent in Kotlin Android
try {
val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "Hello Swapz")
putExtra("jid", "${data.phone}@s.whatsapp.net")
type = "text/plain"
setPackage("com.whatsapp")
}
startActivity(sendIntent)
}catch (e: Exception){
@IhwanID
IhwanID / main.swift
Created February 7, 2023 23:35
Self Sizing CollectionView
if let collectionViewLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
collectionViewLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
}
@IhwanID
IhwanID / SwiftUIWebView.swift
Created December 13, 2020 07:14
SwiftUI Webview Using WKWebView & Webkit
//
// WebView.swift
// SwiftUIWebView
//
// Created by Ihwan ID on 13/12/20.
//
import SwiftUI
import WebKit
@IhwanID
IhwanID / news.json
Created March 8, 2022 14:27
Mock JSON NewsAPI
{"status":"ok","totalResults":38,"articles":[{"source":{"id":null,"name":"Kompas.com"},"author":"Rendika Ferri Kurniawan","title":"Fakta-fakta 8 Planet di Tata Surya dan Kemungkinan Planet Kesembilan - Kompas.com - KOMPAS.com","description":"Ada planet-planet yang bergerak tak searah jarum jam, bahkan porosnya miring. Ada juga yang berwarna merah tapi justru dingin. Ini fakta-fakta planet.","url":"https://www.kompas.com/tren/read/2022/03/08/193100965/fakta-fakta-8-planet-di-tata-surya-dan-kemungkinan-planet-kesembilan","urlToImage":"https://asset.kompas.com/crops/zJuFpHFHSpTLKGj4GElqaUkMx1s=/150x4:835x460/780x390/filters:watermark(data/photo/2020/03/10/5e6775d554370.png,0,-0,1)/data/photo/2021/04/19/607cec3127dfa.jpg","publishedAt":"2022-03-08T12:31:00Z","content":null},{"source":{"id":null,"name":"Kompas.com"},"author":"Reska K. Nistanto","title":"Cara Nonton Apple Event Malam Ini, iPhone SE 3 Bakal Meluncur? - Kompas.com - Tekno Kompas.com","description":"Apple akan menggelar acara peluncuran bertajuk 'Peek
@IhwanID
IhwanID / Converter.kt
Created October 9, 2018 17:38
Format Rupiah dengan kotlin
class Converter {
companion object {
fun rupiah(number: Double): String{
val localeID = Locale("in", "ID")
val numberFormat = NumberFormat.getCurrencyInstance(localeID)
return numberFormat.format(number).toString()
}
}
}
@IhwanID
IhwanID / main.c
Last active September 18, 2021 00:35
Program nama bulan dengan if-else dalam bahasa C
#include <stdio.h>
int
main ()
{
int nomor_bulan;
printf ("Masukkan Angka Bulan (1-12) : ");
scanf ("%d", &nomor_bulan);
if (nomor_bulan == 1)
@IhwanID
IhwanID / test.swift
Created August 27, 2021 22:39
Track Memory Leaks Unit Test with XCTestCase Extension
import XCTest
extension XCTestCase{
func trackMemoryLeaks(_ instance: AnyObject, file: StaticString = #file, line: UInt = #line){
addTeardownBlock { [weak instance] in
XCTAssertNil(instance, "Instance should have been deallocated. Potential memory leak.", file: file, line: line)
}
}
}
@IhwanID
IhwanID / main.swift
Last active August 17, 2021 12:29
Intro to Dependency Diagrams and Composition
import UIKit
class FeedViewController: UIViewController{
var loadFeed: ((([String]) -> Void) -> Void)!
convenience init(loadFeed: @escaping (([String]) -> Void) -> Void){
self.init()
self.loadFeed = loadFeed
}