Skip to content

Instantly share code, notes, and snippets.

@andatta
andatta / build.gradle.kts
Created November 23, 2020 13:17
Sample build.gradle file for showing Cocopaods integration in a Kotlin multiplatform project
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("native.cocoapods")
kotlin("multiplatform")
}
version = "1.0.0"
kotlin {
@andatta
andatta / Wifi.java
Created November 21, 2020 07:05
New WiFi APIs on Android 10
public void connect(String ssid, String password) {
NetworkSpecifier networkSpecifier = new WifiNetworkSpecifier.Builder()
.setSsid(ssid)
.setWpa2Passphrase(password)
.setIsHiddenSsid(true) //specify if the network does not broadcast itself and OS must perform a forced scan in order to connect
.build();
NetworkRequest networkRequest = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.setNetworkSpecifier(networkSpecifier)
.build();
public abstract class SampleReactActivity extends Activity implements DefaultHardwareBackBtnHandler,
PermissionAwareActivity {
private final SampleReactActivityDelegate mDelegate;
protected SampleReactActivity() {
mDelegate = createReactActivityDelegate();
}
/**
@andatta
andatta / CalculateAge.swift
Created May 23, 2017 05:46
Swift code to calculate age in years, months and days from a person's dob
func calculateAge(dob : String) -> (year :Int, month : Int, day : Int){
let df = NSDateFormatter()
df.dateFormat = "yyyy-MM-dd"
let date = df.dateFromString(dob)
guard let val = date else{
return (0, 0, 0)
}
var years = 0
var months = 0
var days = 0
/*The trick is to adopt the protocol UICollectionViewDelegateFlowLayout
and implement the following method*/
//UICollectionViewDelegateFlowLayout method
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
//specify height as per your requirement
return CGSize(width: collectionView.bounds.width, height: 120)
}
/*code snippet shows how we can delete items from collection view without reloading it
the below function is attcahed as selector to a button embedded in collection view cell*/
func removeItem(sender : UIButton){
if let collectionViewCell = sender.superview?.superview as? UICollectionViewCell{
if let indexPath = self.docsCollectionView.indexPathForCell(collectionViewCell){
self.items.removeAtIndex(indexPath.row)
self.collectionView.deleteItemsAtIndexPaths([indexPath])
}
}
}
let items = [String]()
items.append("Swift")
self.collectionView.insertItemsAtIndexPaths([NSIndexPath(forRow: self.items.count - 1, inSection: 0)])