Skip to content

Instantly share code, notes, and snippets.

View ergunkocak's full-sized avatar

Ergün KOÇAK ergunkocak

  • Cologne, Germany
View GitHub Profile
@ahcode0919
ahcode0919 / Swift-Codable.swift
Created June 6, 2017 22:53
Swift 4 Codable example (Type -> JSON)
//Simple Type - Person
struct Person: Codable {
let name: String
let age: Int
func getString() -> String {
return "Name: \(name), Age: \(age)"
}
}
@craigvantonder
craigvantonder / flush-dns.sh
Last active February 3, 2021 04:42
Flushing the DNS in Ubuntu 16.04
#!/bin/bash
# NB: First install nscd with sudo apt-get install nscd
# run this command to flush dns cache:
sudo /etc/init.d/dns-clean restart
# or use:
sudo /etc/init.d/networking force-reload
# Flush nscd dns cache:
sudo /etc/init.d/nscd restart
@jochenschoellig
jochenschoellig / ChatCollectionViewFlowLayout.swift
Created January 19, 2017 15:49
A subclass of UICollectionViewFlowLayout to get chat behavior without turning collection view upside-down. This layout is written in Swift 3 and absolutely usable with RxSwift and RxDataSources because UI is completely separated from any logic or binding.
import UIKit
class ChatCollectionViewFlowLayout: UICollectionViewFlowLayout {
private var topMostVisibleItem = Int.max
private var bottomMostVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?
@steipete
steipete / ios-xcode-device-support.sh
Last active October 14, 2024 16:35
Using iOS 15 devices with Xcode 12.5 (instead of Xcode 13)
# The trick is to link the DeviceSupport folder from the beta to the stable version.
# sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
# Support iOS 15 devices (Xcode 13.0) with Xcode 12.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/15.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
# Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
# (A similar approach works for older versions too, just change the version number after DeviceSupport)
@antonyharfield
antonyharfield / UIWindow+AnimatedRootViewController.swift
Last active November 2, 2017 10:41
Swift category/extension for animating the switch/swap to a new root view controller at the UIWindow level
// Swift category/extension for animating between rootViewControllers at the UIWindow level
import UIKit
extension UIWindow {
func setRootViewController(newRootViewController: UIViewController, animated: Bool) {
// No animation required
if !animated || self.rootViewController == nil {
@soffes
soffes / WebCredential.swift
Last active November 25, 2022 08:24
Easily access Shared Web Credentials
import Foundation
import Security
struct SharedWebCredentials {
// MARK: - Types
struct Credential {
let domain: String
let account: String
@chriseidhof
chriseidhof / TypedExpr.swift
Last active February 3, 2018 23:01
Typed Expressions in Swift
// Variables just contain an integer. We can have a maximum of `Int.max` variables in our program. ¯\_(ツ)_/¯
private struct Var {
static var freshVarIx = 0
let ix: Int
init() {
Var.freshVarIx+=1
ix = Var.freshVarIx
}
}
@phongsakornp
phongsakornp / CollectionView Batch Update
Last active July 10, 2024 00:17
#swift, `Reload CollectionView With Smooth Animation`
// Reload data with animation.
// http://stackoverflow.com/a/15165733
self.collectionView.performBatchUpdates(
{
self.collectionView.reloadSections(NSIndexSet(index: 0))
}, completion: { (finished:Bool) -> Void in
})
@viktorbenei
viktorbenei / script_content.sh
Last active October 13, 2021 15:35
List available shared Schemes in an Xcode Project/Workspace file
#!/bin/bash
echo "=== List of available, **shared** Schemes ==="
set -x
# if you use a Workspace (.xcworkspace) file
xcodebuild -workspace $BITRISE_PROJECT_PATH -list
# or if you use a Project file (.xcodeproj) instead
xcodebuild -project $BITRISE_PROJECT_PATH -list
set +x
echo "============================================="
@eneim
eneim / BadgeTabLayout.java
Last active June 10, 2022 11:27
A custom TabLayout with badge support for Tabs
package im.ene.lab.android.widgets;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.util.AttributeSet;