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 / 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 / CustomFocusView.swift
Created November 6, 2015 10:30
Creating a custom focus view for tvOS
//
// FocusView.swift
// CustomNavigation
//
// Creating a CustomFocusView
// This code shows how to implement a custom view that can be focused in tvOS
// Just set this class as an UIView's custom class
//
import UIKit
@dedeexe
dedeexe / trim.cpp
Last active May 31, 2021 18:08
Trimming string in C++
#include <string>
#include <iostream>
//
//Left trim
//
std::string trim_left(const std::string& str)
{
const std::string pattern = " \f\n\r\t\v";
return str.substr(str.find_first_not_of(pattern));
@dedeexe
dedeexe / URLRequest+curlCommand.swift
Last active April 17, 2020 13:08
Convert URL Request to curl command
extension URLRequest {
public func curl(pretty:Bool = false) -> String {
var data : String = ""
let complement = pretty ? "\\\n" : ""
let method = "-X \(self.httpMethod ?? "GET") \(complement)"
let url = "\"" + self.url?.absoluteString ?? "" + "\""
var header = ""
@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 / StringMaskFormatter.swift
Last active July 12, 2019 11:34
Simples And Fast String Mask Formatter.
//
// StringMaskFormatter.swift
// StringMaskFormatter
//
// Created by dede.exe on 10/07/16.
// It's totally base on article : "http://vojtastavik.com/2015/03/29/real-time-formatting-in-uitextfield-swift-basics/"
// And I don't mind if the original author should allow me(or not) to publish it :)... But I'll keep the reference
//
import UIKit
@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 / UITextField+MaskPattern.swift
Last active November 16, 2018 21:14
Adding Mask to a TextField
//
// UITextField+MaskPattern.swift
// MaskedTextField
//
// Created by dede.exe on 10/07/16.
//
// It's totally base on article : "http://vojtastavik.com/2015/03/29/real-time-formatting-in-uitextfield-swift-basics/"
// And I don't mind if the original author allow me to publish it :)... But I'll keep the reference
// I modified the original implementation to keep it as an Extension...
//