Skip to content

Instantly share code, notes, and snippets.

View albertoramonj's full-sized avatar

Alberto R. albertoramonj

View GitHub Profile
@dfreniche
dfreniche / select-xcode.sh
Last active October 11, 2017 19:41
Rather crude script to change between Xcode 8 and Xcode 9 selecting the correct command line tools
#!/bin/bash
# if 1st param empty...
if [ -z "$1" ]
then
echo "Usage: select-xcode {8|9}"
exit
fi
XCODE8_APP=/Applications/Xcode-8.app
@hemangshah
hemangshah / MyLabel.swift
Created August 24, 2017 09:44
Observe Text changes in UILabel in Swift
class MyLabel: UILabel {
var textWillChange:((_ oldText: String?)->())? = nil
var textDidChange:((_ newText: String?)->())? = nil
override var text: String? {
willSet {
if textWillChange != nil {
textWillChange!(self.text)
}
}
didSet {
@Ben-G
Ben-G / L10NTests.swift
Created June 16, 2017 20:35
Very simple automated test to ensure localizations exist and are well-formed on iOS.
import Foundation
import XCTest
/// Basic sanity check that ensures that we are able to retrieve localized strings for all languages
/// we support.
final class L10NTests: XCTestCase {
func testLocalizations() {
let locales = ["en", "es", "zh-Hans", "zh-Hant", "fi"]
for locale in locales {
@tatimagdalena
tatimagdalena / DateComparison.swift
Last active June 5, 2023 06:41
Compare two dates depending on granularity.
let granularity = Calendar.Component.day
let comparisonResult = Calendar.current.compare(firstDate, to: secondDate, toGranularity: granularity)
// granularity:
// .second
// .minute
// .hour
// .day
// .month
// .year
@mystygage
mystygage / docker-compose.yml
Created March 6, 2017 21:02
Microsoft SQL Server in Docker with data volume
version: '3'
services:
mssql-server-linux:
image: microsoft/mssql-server-linux:latest
volumes:
- mssql-server-linux-data:/var/opt/mssql/data
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=${SQLSERVER_SA_PASSWORD:-yourStrong(!)Password}
@dduan
dduan / migrate.py
Created October 25, 2016 00:10
Migrate Xcode 8.0 style comment to Xcode 8.1 style
# usage:
# IFS=$'\n' find ROOT_SOURCE_FOLDER -name "*.swift" -exec python PATH/TO/migrate.py {} \;
import sys
import re
func = re.compile('func\s+\w+\(')
param = re.compile('(?P<indent>\s*)/// -[ ]*[pP]arameter[ ]+(?P<name>\w+)[ ]*:(?P<description>[^\n]+)\n')
ret = re.compile('(?P<indent>\s*)/// -[ ]*[rR]eturns[ ]*:(?P<description>[^\n]+)\n')
continuation = re.compile('\s*///(?P<description>[^\n]+)')
@cmoulton
cmoulton / Custom HTTP Headers with Swift and Alamofire.swift
Last active July 15, 2022 12:37
Custom HTTP Headers with Swift 3 or 4 and Alamofire 4.0-4.7: See https://grokswift.com/custom-headers-alamofire4-swift3/ for explanations
// MARK: - Adding a header to a single request
func doRequestWithHeaders1() {
let headers: HTTPHeaders = [
"X-Mashape-Key": MY_API_KEY,
"Accept": "application/json"
]
Alamofire.request("https://mashape-community-urban-dictionary.p.mashape.com/define?term=smh", headers: headers)
.responseJSON { response in
debugPrint(response)
@rd13
rd13 / .swift
Last active September 11, 2022 17:00
Copy database file from bundle to documents in Swift 3
func copyDatabaseIfNeeded() {
// Move database file from bundle to documents folder
let fileManager = FileManager.default
let documentsUrl = fileManager.urls(for: .documentDirectory,
in: .userDomainMask)
guard documentsUrl.count != 0 else {
return // Could not find documents URL
@mpneuried
mpneuried / Makefile
Last active July 4, 2025 23:21
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
@djmaze
djmaze / docker-compose.yml
Created September 19, 2016 22:03
Using an ssh-agent container in conjunction with docker-compose
# This compose file mounts an SSH agent socket from the named volume "ssh" into a Ruby container.
# The SSH_AUTH_SOCK variable is set so everything just works.
app:
image: ruby
volumes:
- ssh:/ssh
environment:
SSH_AUTH_SOCK: /ssh/auth/sock