Skip to content

Instantly share code, notes, and snippets.

View joncardasis's full-sized avatar
🔬
📱 Probing iOS internals...

Jon Cardasis joncardasis

🔬
📱 Probing iOS internals...
View GitHub Profile
@joncardasis
joncardasis / WebServer.py
Created February 7, 2017 21:08
A simple and quick HTTP web server in Python
"""
Author: Jonathan Cardasis
"""
import socket
import signal # Allow socket destruction on Ctrl+C
import sys
import time
import threading
@joncardasis
joncardasis / Measure.swift
Last active January 26, 2018 00:26
My Swift 3 Measure Execution time function using GCD
func measureBlock(_ description: String, numberOfExecutes: Int = 1, block: () -> Void) {
let start = DispatchTime.now()
for _ in 0..<numberOfExecutes {
block()
}
let end = DispatchTime.now()
let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds
let secondsTime = (Double(nanoTime)/1000000000.0)
@joncardasis
joncardasis / LinguisticsFix.md
Last active April 24, 2017 15:57
Fix GitHub Displaying Incorrect Languages in Repo

Fix Linguistics in Your Repo

Sometimes GitHub will mismark your repo's languages.

I had a C++ project displaying that a large portion was Objective-C because of a single header file from SQLite3.h.

Step 1:

Create a .gitattributes file in your root. Mine looks like this:

@joncardasis
joncardasis / GitFix.md
Last active May 1, 2017 16:28
A list of git commands that I found very helpful and should remember.

Rewriting Commit History

This will rewrite the branch's commit history and is useful for combining users if two emails were used for a single user at any point.

Note: Since this edits all history, everyone will need to re-clone the repo in order to get the correct history on their local machines.

A list of users who committed can be viewed via git shortlog -s -n.

$ git filter-branch --commit-filter '
    if [ "$GIT_AUTHOR_EMAIL" = "jonViaDesktop@localhost" ];
 then
@joncardasis
joncardasis / setIcon.sh
Created May 3, 2017 16:00
Set the Finder icon of a single file in macOS
#!/bin/sh
# Sets an icon for a file
# Parameters:
# $1 icon_source - file path to the icon soruce (a .icns file)
# $2 file_path - file path the the destination file to change the icon of
icon_source=$1
file_path=$2
generated_icon=".icon.rsrc"
@joncardasis
joncardasis / BasicAnimation.swift
Last active May 31, 2017 19:52
[Medium Gists] CATransaction Medium Post
let cornerAnimation = CABasicAnimation(keyPath: #keyPath(CALayer.cornerRadius))
cornerAnimation.fromValue = oldValue
cornerAnimation.toValue = newValue
cornerAnimation.duration = 1.0
styledButton.layer.cornerRadius = newValue
styledButton.layer.add(cornerAnimation, forKey: #keyPath(CALayer.cornerRadius))
@joncardasis
joncardasis / Transaction.swift
Created May 31, 2017 19:52
[Medium Gists] CATransation
CATransaction.begin()
CATransaction.setAnimationDuration(0.5)
styledButton.layer.opacity = 0.5
styledButton.layer.backgroundColor = UIColor.white.cgColor
CATransaction.commit()
@joncardasis
joncardasis / ComplexTransaction.swift
Created May 31, 2017 20:07
[Medium Gists] Complex Transaction
let oldValue = styledButton.frame.width/2
let newButtonWidth: CGFloat = 60
/* Do Animations */
CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut))
// View animations
UIView.animate(withDuration: 2.0) {
@joncardasis
joncardasis / CustomTimingFunction.swift
Last active May 31, 2017 20:21
[Medium Gists] Custom CATransaction Timing Function
let timingFunction = CAMediaTimingFunction(controlPoints: 0.65, -0.55, 0.27, 1.55)
//...
CATransaction.setAnimationTimingFunction(timingFunction)
//... Do your UIKit animation
@joncardasis
joncardasis / CommonAnimation.swift
Created May 31, 2017 20:37
[Medium Gists] Common Animation Pattern
UIView.animate(withDuration: 1.0) {
self.button.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
}