Skip to content

Instantly share code, notes, and snippets.

View dedeexe's full-sized avatar

dede.exe dedeexe

  • PuraMagia Labs
  • Brazil
View GitHub Profile
@dedeexe
dedeexe / CaesarCipher.swift
Created August 3, 2024 14:09
A simple example of Caesar Cipher made in swift
struct CaesarCipher {
enum Operation {
case encode
case decode
}
let charTable: [Character]
private func crypt(text: String, shift: Int, operation: Operation) -> String {
var result: [Character] = []
@dedeexe
dedeexe / GetWindowList.swift
Created March 23, 2023 18:24
A function to get the list of windows in MacOS using Swift
func getWindowsList() {
let options = CGWindowListOption(arrayLiteral: .optionOnScreenOnly)
let windowListInfo = CGWindowListCopyWindowInfo(options, CGWindowID(1))
let infoList = windowListInfo as! [[String: Any]]
let windowList = infoList.filter { (($0["kCGWindowLayer"] as? Int) ?? -1) == 0 }
for window in windowList {
print(window["kCGWindowOwnerName"])
}
@dedeexe
dedeexe / multipart_formdata.swift
Created January 30, 2023 12:32
A basic showing multipart/form-data implementation using swift.
import UIKit
import Foundation
let image = UIImage(named: "example.jpg")
let imageData = image!.jpegData(compressionQuality: 0.75)
let date = Date()
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let dateString = dateFormatter.string(from: date)
@dedeexe
dedeexe / SignalTrap.swift
Last active January 8, 2020 03:03
How to trap OS signals using swift
enum SignalTrap {
typealias SignalHandler = @convention(c)(Int32) -> Void
static func handle(signal:Int32, action: @escaping SignalHandler) {
typealias SignalAction = sigaction
var sigAction = sigaction()
sigAction.__sigaction_u = unsafeBitCast(action, to: __sigaction_u.self)
sigaction(signal, &sigAction, nil)
@dedeexe
dedeexe / DynamicFunctions.swift
Created April 25, 2019 18:34 — forked from neonichu/DynamicFunctions.swift
Using dlopen / dlsym to call C functions from Swift
import Darwin
let handle = dlopen("/usr/lib/libc.dylib", RTLD_NOW)
let sym = dlsym(handle, "random")
let functionPointer = UnsafeMutablePointer<() -> CLong>(sym)
let result = functionPointer.memory()
println(result)
@dedeexe
dedeexe / database.rules.json
Created November 17, 2018 13:26 — forked from codediodeio/database.rules.json
Common Database Rules for Firebase
// No Security
{
"rules": {
".read": true,
".write": true
}
}
@dedeexe
dedeexe / countrycodes.json
Created October 26, 2018 12:26
A JSON with all country codes.
[
{
"name":"Afghanistan",
"dial_code":"+93",
"code":"AF"
},
{
"name":"Åland Islands",
"dial_code":"+358",
"code":"AX"
@dedeexe
dedeexe / Data+hash
Created September 18, 2018 11:31
Hash using Swift + Common Crypto
//
// Data+hash.swift
// HashTools
//
// Created by dede.exe on 17/09/18.
// Copyright © 2018 dede.exe. All rights reserved.
//
import Foundation
@dedeexe
dedeexe / Data+MimeType.swift
Created August 20, 2018 14:10
Data MimyType analyse extension
import Foundation
import MobileCoreServices
extension Data {
enum MimeType : Int {
case imageJPEG = 0xff
case imagePNG = 0x89
case applicationPDF = 0x25
@dedeexe
dedeexe / user.swift
Last active June 23, 2018 18:59
User model example
{ "name":"Jose", "age":33, "height": 1.70, "weigh":70 }