Skip to content

Instantly share code, notes, and snippets.

@christianascone
christianascone / UIView+Extension.swift
Last active October 7, 2021 08:54
UIView extension for setting an hexagonal mask on layer
import Foundation
// http://sapandiwakar.in/make-hexagonal-view-on-ios/
extension UIView {
/// Set the view layer as an hexagon
func setupHexagonView() {
let lineWidth: CGFloat = 5
let path = self.roundedPolygonPath(rect: self.bounds, lineWidth: lineWidth, sides: 6, cornerRadius: 10, rotationOffset: CGFloat(.pi / 2.0))
@christianascone
christianascone / PrintFonts.swift
Last active June 16, 2017 07:42
Prints every font installed in the app
// http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app
print("==== BEGIN INSTALLED FONT ====")
// Print every installed font
for family: String in UIFont.familyNames {
print("\(family)")
for names: String in UIFont.fontNames(forFamilyName: family) {
print("== \(names)")
}
}
@christianascone
christianascone / oracleFreeSpace.sql
Created June 15, 2017 17:46
Check free space on Oracle XE
--- https://stackoverflow.com/a/5448736/5746936
SELECT /* + RULE */ df.tablespace_name "Tablespace",
df.bytes / (1024 * 1024) "Size (MB)",
SUM(fs.bytes) / (1024 * 1024) "Free (MB)",
Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free",
Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used"
FROM dba_free_space fs,
(SELECT tablespace_name,
SUM(bytes) bytes
@christianascone
christianascone / build.gradle
Created June 16, 2017 07:25
Gradle instruction for renaming apk with app version
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def version = defaultConfig.versionName
//version = version.replaceAll('\\.', '_')
def fileName = "appName_v" + version + ".apk"
if(variant.name.equals("variantName")){
fileName = "appName_variant_v" + version + ".apk"
}
@christianascone
christianascone / UIViewController+Extension.swift
Created June 16, 2017 10:04
UIViewController extension with functions for showing OnBoarding and setting as 'done' using UserDefaults
//
// UIViewController+Extension.swift
//
// Created by Christian Ascone on 16/06/17.
//
import Foundation
import KVNProgress
import Onboard // https://github.com/mamaral/Onboard
@christianascone
christianascone / VersionUtils.swift
Last active June 21, 2017 08:38
Version Utils class for finding info about app version and build number
//
// VersionUtils.swift
//
// Created by Christian Ascone on 21/06/2017.
// Copyright © 2017 Christian Ascone. All rights reserved.
//
import Foundation
class VersionUtils {
@christianascone
christianascone / UILabel+Truncate.swift
Created June 21, 2017 10:51
UILabel extension for truncated state
//
// UILabel+Extension.swift
// ShopAdvisor
//
// Created by Christian Ascone on 21/06/2017.
// Copyright © 2017 Luna srls. All rights reserved.
//
import Foundation
@christianascone
christianascone / archiveXcodeProjectWithPods.sh
Last active March 16, 2022 02:59
Archive a project with Cocoapods dependencies
#!/bin/bash
PROJECT_NAME="$(ls -d *.xcworkspace* | cut -d'.' -f1)"
# REF: https://bitbar.com/tipstricks-how-to-archive-and-export-ipa-from-script/
# Clean project
echo "#### CLEAN ####"
xcodebuild clean -workspace "${PROJECT_NAME}".xcworkspace -configuration Release -scheme "${PROJECT_NAME}"
# Archive
echo "#### ARCHIVE ####"
xcodebuild archive -workspace "${PROJECT_NAME}".xcworkspace -configuration Release -scheme "${PROJECT_NAME}" -archivePath "${PROJECT_NAME}".xcarchive
# Export ipa
@christianascone
christianascone / p12ToPem.sh
Created July 10, 2017 07:48
Convert a p12 push certificate to PEM file
openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts
@christianascone
christianascone / MathRoundUtil.java
Created July 12, 2017 13:55
Java utils for a few (less used) methods used for number rounding
/**
* Util class for number rounding
*
* @author Christian Ascone
*
*/
public class MathRoundUtil {
/**
* Rounds a double number to the closest 0.5 divisor.
* For example: