Skip to content

Instantly share code, notes, and snippets.

View pietrorea's full-sized avatar
✌️

Pietro Rea pietrorea

✌️
View GitHub Profile
@pietrorea
pietrorea / gist:8309d74336bd82c127ae
Created December 7, 2014 22:37
Cast Swift closure as Objective-C block (needed for JavaScriptCore)
var block : @objc_block (NSString!) -> Void = {
[unowned self] (string : NSString!) -> Void in
let jsText = "\(string)\n"
self.outputTextView.setText(jsText, concatenate: true)
}
context.setObject(unsafeBitCast(block, AnyObject.self),
forKeyedSubscript: "print")
@pietrorea
pietrorea / xcci.md
Created October 26, 2015 16:35 — forked from quellish/xcci.md
Xcode CI script variables

Variable

Type

@pietrorea
pietrorea / UIViewController+Containment.swift
Created November 12, 2015 18:56
UIViewController+Containment.swift
import UIKit
extension UIViewController {
func addChildVC(viewController: UIViewController) {
addChildViewController(viewController)
view.addSubview(viewController.view)
viewController.didMoveToParentViewController(self)
}
}
func poll() {
let backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
let source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, backgroundQueue)
let interval: UInt64 = UInt64(10) * NSEC_PER_SEC
let leeway: UInt64 = UInt64(0.1) * NSEC_PER_SEC
dispatch_source_set_timer(source, DISPATCH_TIME_NOW, interval, leeway)
dispatch_source_set_event_handler(source) { () -> Void in
self.pollDidFinish(source: source)
Verifying my Blockstack ID is secured with the address 13XP5d1aPsUQZHt55f3WyYMCHvaWQjgDKu https://explorer.blockstack.org/address/13XP5d1aPsUQZHt55f3WyYMCHvaWQjgDKu
@pietrorea
pietrorea / UIImage+Extension.m
Created April 16, 2020 03:13
UIImage from UIColor
#import "UIImage+Extension.h"
@implementation UIImage (Extension)
- (UIImage *)imageWithColor:(UIColor *)color
{
UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, self.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
@pietrorea
pietrorea / gist:8fc2c83a26322f3909ab630aee2f5414
Created June 25, 2021 16:08
Set initial view controller in code using SceneDelegate
// First, delete the two storyboard entries in the Info.plist (one newer one for SceneDelegate and a newer one for AppDelegate)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else {
return
}
let blueViewController = UIViewController()
blueViewController.view.backgroundColor = .blue
@pietrorea
pietrorea / SampleService.swift
Created July 2, 2021 15:13
Alamofire 5.43 `responseDecodable` example
static func load(_ entityId: Int, completion: @escaping ( (SampleServiceResponse?) -> Void)) {
let urlString = "https://api.sweetpeamobile.com/v1/sampleService?locationId=\(locationId)"
AF.request(urlString).responseDecodable(of: SampleServiceResponse.self) { response in
switch response.result {
case .success(let decodedResponse):
completion(decodedResponse)
case .failure(let error):
print("Networking error: \(error.localizedDescription)")
completion(nil)
}
@pietrorea
pietrorea / script_mysql_secure_installation.sh
Created October 22, 2021 20:01
Installs mysql 8, secures it, creates a user and db
#!/bin/bash
set -e
# Sets up an new myql instalation (Ubuntu 20.04)s
# 1. Downloads mysql-server if necessary
# 2. Secures the installation
# 3. Sets the root password
# 4. Creates an app related DB
@pietrorea
pietrorea / wp-config-additions.php
Last active February 7, 2022 14:46
Wordpress wp-config.php - running behind a reverse proxy that terminates SSL
define( 'WP_HOME', 'https://yoursite.com/blog');
define( 'WP_SITEURL', 'https://yoursite.com/blog');
/**
* This is needed for a reverse proxy setup that terminates SSL and forwards /blog to another host.
* Without it, the Wordpress host doesn't know that it needs to make requests to itself using https.
*/
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}