Skip to content

Instantly share code, notes, and snippets.

Avatar

Łukasz Sypniewski L-Sypniewski

View GitHub Profile
@L-Sypniewski
L-Sypniewski / chromiumRunDebug.sh
Created Nov 1, 2020
Run Chromium in debug mode
View chromiumRunDebug.sh
chromium-browser --remote-debugging-port=9222 --user-data-dir="/home/[User]/Documents/ChromiumDataWebDriver"
@L-Sypniewski
L-Sypniewski / TextFieldWithImage.swift
Created Nov 9, 2018
UITextField with image and padding
View TextFieldWithImage.swift
import UIKit
@IBDesignable
class TextFieldWithImage: UITextField {
override func leftViewRect(forBounds bounds: CGRect) -> CGRect {
return super.leftViewRect(forBounds: bounds)
}
@IBInspectable var leftImage: UIImage? {
@L-Sypniewski
L-Sypniewski / ServicesEnableDisable.bat
Created Oct 29, 2018
Start/Stop Windows Services with administrative privileges using .bat file
View ServicesEnableDisable.bat
@echo off
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)
@L-Sypniewski
L-Sypniewski / Swift_QuickNimble_SharedExample.swift
Created Sep 4, 2018
Swift Quick/Nimble SharedExample without creating a separate class
View Swift_QuickNimble_SharedExample.swift
context("some context") {
let someSharedExample = "someSharedExampleID"
sharedExamples(someSharedExample) { (sharedExampleContext: @escaping SharedExampleContext) in
it("checks something") {
let message = sharedExampleContext()["message"] as! String
View ChainObservables.swift
//If you have 2 "rx" variables (drivers, observables etc) you can often chain them
//without a need to write code in subscribe close. For example:
someObject.loadingState
.drive(loadingStateMutable)
.disposed(by: disposeBag)
//This will apply values from someObject.loadingState to a loadingStateMutable variable in a viewModel
@L-Sypniewski
L-Sypniewski / JSONParser.swift
Created Mar 15, 2018
Parse local JSON using Codable protocol
View JSONParser.swift
import Foundation
class JSONParser {
static func parse<T>(from localJSONFileName: String) throws -> T? where T: Decodable {
do {
let localFilePath = Bundle.main.path(forResource: localJSONFileName, ofType: "json")!
let jsonString = try NSString(contentsOfFile: localFilePath, encoding: String.Encoding.utf8.rawValue)
let jsonData = jsonString.data(using: String.Encoding.utf8.rawValue)!
let decoder = JSONDecoder()
let decodedData = try! decoder.decode(T.self, from: jsonData)
@L-Sypniewski
L-Sypniewski / deleteAllEntitiesFromPersistence.swift
Last active Sep 23, 2020
Swift - delete all entities from persistent storage using NSFetchedResultsController
View deleteAllEntitiesFromPersistence.swift
/ Prepare NSFetchedResultsController
fileprivate lazy var fetchedResultsController: NSFetchedResultsController<Article> = {
// Create Fetch Request
let fetchRequest: NSFetchRequest<Article> = Article.fetchRequest()
// Configure Fetch Request
fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(Article.sourceName), ascending: true)]
// Create Fetched Results Controller
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.persistentContainer.viewContext, sectionNameKeyPath: nil/*#keyPath(Article.sourceName)*/, cacheName: nil)
@L-Sypniewski
L-Sypniewski / deleteAllEntities.swift
Created Feb 26, 2018
Swift - delete all entities using NSFetchedResultsController
View deleteAllEntities.swift
// Prepare NSFetchedResultsController
fileprivate lazy var fetchedResultsController: NSFetchedResultsController<Article> = {
// Create Fetch Request
let fetchRequest: NSFetchRequest<Article> = Article.fetchRequest()
// Configure Fetch Request
fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(Article.sourceName), ascending: true)]
// Create Fetched Results Controller
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.persistentContainer.viewContext, sectionNameKeyPath: nil/*#keyPath(Article.sourceName)*/, cacheName: nil)