Skip to content

Instantly share code, notes, and snippets.

View raygun101's full-sized avatar
💭
Coding like Mad Cat 🦑

Leslie Godwin raygun101

💭
Coding like Mad Cat 🦑
View GitHub Profile
import SwiftUI
import AVKit
import CoreImage
import CoreImage.CIFilterBuiltins
struct ContentView: View {
@State private var currentFilter = 0
var filters : [CIFilter?] = [nil, CIFilter.sepiaTone(), CIFilter.pixellate(), CIFilter.comicEffect()]
@raygun101
raygun101 / CommandlineSplittingConverter.dart
Last active September 14, 2020 11:13
🍰 Layered Cakewalk [Dart] - Parses/splits a command-line String into a List<String> of the individual argument elements processing quotes.
//
// Original implementation: https://stackoverflow.com/a/39177861/638848
//
// Re-made by: Leslie Godwin (leslie.godwin@gmail.com)
import 'dart:convert';
/// Parses/splits a command-line String into a List<String> of the individual argument elements.
/// Handles whitespace, quotes and back\slash escape.
///
//#! Swift 5
import Foundation
import AppKit
////////////////////////////////////////////////////////////////////
//: ## Type Definition
struct AttrString {
let attributedString: NSAttributedString
@harlanhaskins
harlanhaskins / StringScanner.swift
Last active August 4, 2020 23:45
Swift String Scanner
import Foundation
/// `StringScanner` is a fast scanner for Strings and String-like objects.
/// It's used to extract structured bits from unstructured strings, while
/// avoiding making extra copies of string bits until absolutely necessary.
/// You can build Scanners over Substrings, allowing you to scan
/// parts of strings and use smaller, more specialized scanners to extract bits
/// of that String without needing to reuse another scanner.
public struct StringScanner<Input: StringProtocol> {
let input: Input
@harlanhaskins
harlanhaskins / Lexer.swift
Last active March 4, 2023 20:10
Building a Compiler in Swift with LLVM, Part 1: Introduction and the Lexer
#if os(macOS)
import Darwin
#elseif os(Linux)
import Glibc
#endif
enum BinaryOperator: Character {
case plus = "+"
case minus = "-"
case times = "*"
@natecook1000
natecook1000 / operatorCharacters.swift
Last active January 3, 2024 21:33
Allowed characters for Swift operators
import Foundation
extension UnicodeScalar : ForwardIndexType {
public func successor() -> UnicodeScalar {
return UnicodeScalar(value + 1)
}
}
var operatorHeads: [UnicodeScalar] = Array("=-+!*%<>&|^~?".unicodeScalars)
operatorHeads += Array("\u{00A1}" ... "\u{00A7}")
@sharplet
sharplet / ConcatenateSequence.swift
Created February 9, 2015 10:25
Generic concatenation of sequences in Swift
func + <S: SequenceType, E where S.Generator.Element == E> (lhs: S, rhs: S) -> GeneratorOf<E> {
var (g, h) = (lhs.generate(), rhs.generate())
return GeneratorOf {
g.next() ?? h.next()
}
}
@ktym
ktym / unwebarchive.rb
Created February 12, 2013 18:03
Extract contents of a .webarchive file.
#!/usr/bin/env ruby
#
# Mac OS X webarchive is a binary format of a plist file. You can extract the contents manually:
# 1. convert the plist file into XML by "plutil -convert xml1 file.webarchive"
# 2. parse the resulted XML file by some XML parser
# 3. decode "WebResourceData" by Base64.decode64(data) in each key
# 4. save the decoded content into a file indicated by "WebResourceData"
# Thankfully, the plist library can take care of annoying steps 2 and 3.
#
# Preparation:
@SwarmShepherd
SwarmShepherd / DartReflection
Created November 3, 2012 01:58
Example of using Reflection in Dart
#import('dart:mirrors');
class MyClass {
String _test;
String get test => _test;
set test(String paramVal) => _test = paramVal;
void my_method() {
}
@bkyle
bkyle / NSArray+Globbing.h
Created February 3, 2010 20:02
NSArray+Globbing
#import <Foundation/Foundation.h>
@interface NSArray (Globbing)
+ (NSArray*) arrayWithFilesMatchingPattern: (NSString*) pattern inDirectory: (NSString*) directory;
@end