Skip to content

Instantly share code, notes, and snippets.

@ucotta
ucotta / split_spanish_names.py
Last active July 10, 2024 09:30
Split spanish full name in different fields
def separate_name_surnames(full_name):
# Creamos una copia del nombre reemplazando todas las partículas
modified_name = full_name.lower()
particles = ["de la ", "de los ", "de las ", "del ", "de "]
for particle in particles:
modified_name = modified_name.replace(" " + particle, " " + particle.replace(" ", "_"))
# Dividimos el nombre modificado
parts = modified_name.split()
@ucotta
ucotta / socket.asm
Created March 19, 2021 19:00 — forked from DGivney/socket.asm
NASM socket programming example
; Socket
; Compile with: nasm -f elf socket.asm
; Link with (64 bit systems require elf_i386 option): ld -m elf_i386 socket.o -o socket
; Run with: ./socket
%include 'functions.asm'
SECTION .data
; our response string
response db 'HTTP/1.1 200 OK', 0Dh, 0Ah, 'Content-Type: text/html', 0Dh, 0Ah, 'Content-Length: 14', 0Dh, 0Ah, 0Dh, 0Ah, 'Hello World!', 0Dh, 0Ah, 0h
@ucotta
ucotta / httpd.asm
Created March 19, 2021 19:00 — forked from DGivney/httpd.asm
section .text
global _start
_start:
xor eax, eax ; init eax 0
xor ebx, ebx ; init ebx 0
xor esi, esi ; init esi 0
jmp _socket ; jmp to _socket
_socket_call:
/*
Get animated polyline route:
- https://stackoverflow.com/questions/42620510/how-to-get-animated-polyline-route-in-gmsmapview-so-that-it-move-along-with-map
Get polyline from origin and destination coordinates:
- https://github.com/lukagabric/LRouteController/blob/master/LRouteControllerSample/Classes/LRouteController/LRouteController.m
Draw stroke with some style:
var styles:[GMSStrokeStyle] = [GMSStrokeStyle.solidColor(UIColor.cyan), GMSStrokeStyle.solidColor(UIColor.clear)]
extension UIViewController {
func setAsRootViewController(animated: Bool, completion: (() -> Void)?) {
let appDelegate = UIApplication.shared.delegate as? AppDelegate
if animated {
UIView.transition(with: (appDelegate?.window)!, duration: 0.5, options: .transitionCrossDissolve,
animations: {
let oldState: Bool = UIView.areAnimationsEnabled
UIView.setAnimationsEnabled(false)
appDelegate?.window?.rootViewController = self
@ucotta
ucotta / add_htpasswd_to_nginx.sh
Last active January 24, 2017 11:40
Add httpass authentication to nging
#!/bin/bash
# First step, prepare the .htpasswd file
# Add the user
sh -c "echo -n 'USERNAME:' >> /etc/nginx/.htpasswd"
# Then, add the password
sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
# Now, add it to your location
@ucotta
ucotta / waitUntilWithSleepExample.swift
Created November 10, 2016 10:16
Swift: NSTask with 0% cpu
// This task will run for ever a task get 0% of cpu
// dont use waitUntil because it will consume you cpu
import Foundation
extension Task {
public func waitUntilWithSleep() {
while running {
// sleep for 0.1 seconds
usleep(10000)
}
@ucotta
ucotta / TraversalCharactersString.swift
Last active November 9, 2016 03:25
contaisTraversalCharacters is a extension for String to check when a path may contains an traversal path include attack for Swift 3.0
/*
Avoid usage of files with this characters.
Examples with positive response:
/var/www/templates/../../../etc/passwd
/var/www/templates/%2e%2e%2f%2e%2e%2f%2e%2e%2fetc/passwd
/var/www/templates%252e%252e%252f%252e%252e%252f%252e%252e%252fetc/passwd
/var/www/templates/..%c0%af..%c0%af..%c0%afetc/passwd
With this you cannot do things like this:
/var/www/templates/.htdocs (because /. is not allowed)
@ucotta
ucotta / StringExtensionHTML.swift
Created November 4, 2016 05:31 — forked from mwaterfall/StringExtensionHTML.swift
Decoding HTML Entities in Swift
// Very slightly adapted from http://stackoverflow.com/a/30141700/106244
// 99.99% Credit to Martin R!
// Mapping from XML/HTML character entity reference to character
// From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
private let characterEntities : [String: Character] = [
// XML predefined entities:
""" : "\"",
"&" : "&",