Skip to content

Instantly share code, notes, and snippets.

@ghecho
ghecho / scince_2020.sh
Created October 4, 2021 15:53 — forked from diegovalle/scince_2020.sh
Script to download shapefiles from 2020 Mexican census (including demographic data)
#!/usr/bin/env bash
# Author: Diego Valle-Jones
# Web: http://www.diegovalle.net
# Script to download shapefiles from 2020 Mexican census (including demographic data)
# tested on ubuntu 20.04
# Exit on error, undefined and prevent pipeline errors
set -euo pipefail
IFS=$'\n\t'
# The directory from which the script is running
@ghecho
ghecho / js_linux.py
Created August 14, 2018 01:19 — forked from rdb/js_linux.py
Access joysticks/game controllers from Python in Linux via the joystick driver. See https://www.panda3d.org/forums/viewtopic.php?f=8&t=16767
# Released by rdb under the Unlicense (unlicense.org)
# Based on information from:
# https://www.kernel.org/doc/Documentation/input/joystick-api.txt
import os, struct, array
from fcntl import ioctl
# Iterate over the joystick devices.
print('Available devices:')
@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))
<?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
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] = []
@ghecho
ghecho / bash.sh
Created May 8, 2017 02:15
Linux get Disk Usage for current folder
du -hx --max-depth=1
@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 / 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 / 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 / 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)
{