Skip to content

Instantly share code, notes, and snippets.

View marcetcheverry's full-sized avatar

Marc Etcheverry marcetcheverry

View GitHub Profile

Keybase proof

I hereby claim:

  • I am marcetcheverry on github.
  • I am marcetcheverry (https://keybase.io/marcetcheverry) on keybase.
  • I have a public key ASChScwC2GS1glKbM-JQ_eCEtjCbGgd4vCNEMgTLtbJesgo

To claim this, I am signing this object:

@marcetcheverry
marcetcheverry / String.swift
Last active November 6, 2023 20:22
Convert HTML to Text/String in Swift
extension String {
/// Using regular expressions is not a correct approach for converting HTML to text, there are many pitfalls, like handling <style> and <script> tags. On platforms that support Foundation, one alternative is to use NSAttributedString's basic HTML support. Care must be taken to handle extraneous newlines and object replacement characters left over from the conversion process. It is a good idea to cache complex generated NSAttributedStrings either through storage or NSCache.
func strippingHTML() throws -> String? {
if isEmpty {
return nil
}
if let data = data(using: .utf8) {
let attributedString = try NSAttributedString(data: data,
options: [.documentType : NSAttributedString.DocumentType.html,
@marcetcheverry
marcetcheverry / README.md
Created October 16, 2017 03:19 — forked from yamnikov-oleg/LICENSE
Shared (interprocess) mutexes on Linux

shared_mutex

Microlibrary for inter-process mutexes on Linux.

Example which says it all

#include "shared_mutex.h"
#include <stdio.h>
@marcetcheverry
marcetcheverry / beas.sh
Created March 6, 2016 02:30
beas.sh - Bash Email Admin Script updated for Debian Jessie 8
#!/bin/bash
#####
# beas.sh - Bash Email Admin Script
# Version 0.3 (Jessie edition)
# (c) 2015 Emmanuel Revah - manu-at-manurevah.com
# (c) 2015 Marc - [email protected]
# This script is made to go with the tutorial found here
@marcetcheverry
marcetcheverry / a-mylib.c
Created May 28, 2011 21:42
Mac dylib at runtime
// Compile: clang -dynamiclib -Wl,-current_version 1.0 mylib.c -o mylib.dylib
// See it with otool -L mylib.dylib
//mylib.dylib:
// mylib.dylib (compatibility version 0.0.0, current version 1.0.0)
#include <stdio.h>
__attribute__((constructor))
static void initialize() {
printf("Initializing MyLib\n");
@marcetcheverry
marcetcheverry / mapread.c
Created May 25, 2011 14:05
mmap and read/write string to file
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{