Skip to content

Instantly share code, notes, and snippets.

@ghecho
ghecho / offscreen.m
Last active August 29, 2015 14:14 — forked from chrisjdavis/offscreen.m
- (IBAction)getImageFromWeb:(id)sender {
// grab the width and height of the document in our mobileView.
CGSize contentSize = CGSizeMake(
[[mobileView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth;"] floatValue],
[[mobileView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue]
);
// create a new window, offscreen.
NSWindow *hiddenWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect( -1000,-1000, contentSize.width, contentSize.height )
styleMask: NSTitledWindowMask | NSClosableWindowMask backing:NSBackingStoreNonretained defer:NO];
@ghecho
ghecho / TouchIDViewController.swift
Created January 29, 2015 05:22
ViewController with Touch ID
//
// ViewController.swift
// TouchIDViewController
//
// Created by Diego on 1/28/15.
// Copyright (c) 2015 Diego. All rights reserved.
//
import UIKit
import LocalAuthentication
@ghecho
ghecho / test.php
Created January 29, 2015 06:20
PHP BCrypt
<?PHP
echo better_crypt("password");
if(password_verify("password", better_crypt("password"))) {
// password is correct
echo "<br><br>";
echo "password correct";
}
function better_crypt($input, $rounds = 8)
{
@ghecho
ghecho / mac-remapper.sh
Created September 6, 2015 03:07
Bash function that remaps the computer's MAC
# taken from: http://jezenthomas.com/free-internet-on-trains/
# it goes into the .bashrc
function remac {
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -z
sudo ifconfig en0 ether $(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
sudo networksetup -detectnewhardware
echo $(ifconfig en0 | grep ether)
}
@ghecho
ghecho / gist:94b8bc50a0933c87ce069b1518dfea32
Created April 12, 2017 01:08
MapKit Polygon contains point
// taken from http://stackoverflow.com/a/41923217
extension MKPolygon {
func contain(coor: CLLocationCoordinate2D) -> Bool {
let polygonRenderer = MKPolygonRenderer(polygon: self)
let currentMapPoint: MKMapPoint = MKMapPointForCoordinate(coor)
let polygonViewPoint: CGPoint = polygonRenderer.point(for: currentMapPoint)
return polygonRenderer.path.contains(polygonViewPoint)
}
}
@ghecho
ghecho / gist:c6b4e206a01d1293e9b9dfa20676fc68
Created April 28, 2017 20:04
Change spaces to tabs in Laravel project in Sublime Text
Open Search and Replace
Find: ( {4})
Where: -vendor/*,-bootstrap/*
Replace: \t
@ghecho
ghecho / bash.sh
Created May 8, 2017 02:15
Linux get Disk Usage for current folder
du -hx --max-depth=1
extension NSRegularExpression {
func actuallyUsableMatch(in string: String) -> (fullMatch: String, captures: [String])? {
let nsString = string as NSString
let range = NSMakeRange(0, nsString.length)
guard let match = firstMatch(in: string, range: range) else {
return nil
}
let fullMatch = nsString.substring(with: match.range)
var captures: [String] = []
<?php
$cfdi = '<?xml version="1.0" encoding="UTF-8"?>
<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:nomina="http://www.sat.gob.mx/nomina" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd http://www.sat.gob.mx/nomina http://www.sat.gob.mx/sitio_internet/cfd/nomina/nomina11.xsd" version="3.2" fecha="2015-11-06T18:15:32" folio="123 - 1063" serie="A" subTotal="24113.81" descuento="0.00" motivoDescuento="Deducciones de nómina" total="20000.00" Moneda="MXN" condicionesDePago="Contado" NumCtaPago="No identificado" tipoDeComprobante="egreso" noCertificado="00001000000307566366" certificado="MIIFNzCCBB+gAwIBAgIUMDAwMDEwMDAwMDAzMDc1NjYzNjYwDQYJKoZIhvcNAQELBQAwggGKMTgwNgYDVQQDDC9BLkMuIGRlbCBTZXJ2aWNpbyBkZSBBZG1pbmlzdHJhY2nDs24gVHJpYnV0YXJpYTEvMC0GA1UECgwmU2VydmljaW8gZGUgQWRtaW5pc3RyYWNpw7NuIFRyaWJ1dGFyaWExODA2BgNVBAsML0FkbWluaXN0cmFjacOzbiBkZSBTZWd1cml
@ghecho
ghecho / qr.swift
Last active May 29, 2019 12:32
Generate a QR image from a string using Swift 4
import CoreImage
static func createQR(fromString: String) -> CIImage?
{
let stringData = fromString.data(using: .utf8)
let filter = CIFilter(name: "CIQRCodeGenerator")
filter?.setValue(stringData, forKey: "inputMessage")
filter?.setValue("H", forKey: "inputCorrectionLevel")
let qrCodeImage = filter?.outputImage
let imageByTransform = qrCodeImage?.transformed(by: CGAffineTransform(scaleX: 15.0, y: 15.0))