Skip to content

Instantly share code, notes, and snippets.

@epohs
epohs / Swift find characters
Last active August 29, 2015 14:23
Find all occurances of a character in a string using Swift
let search_str = "l"
let string = "Hello World"
let needle:Character = search_str[search_str.startIndex]
let upper:String = String(needle).uppercaseString
var char_locations:[String] = ["-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"]
for (index, character) in enumerate(Array(string)) {
@epohs
epohs / ncurses.swift
Last active July 7, 2020 01:23
How to setup and use ncurses in a Swift script
#!/usr/bin/env xcrun swift -i
import Foundation
import Darwin.ncurses
initscr() // Init window. Must be first
cbreak()
noecho() // Don't echo user input
nonl() // Disable newline mode
intrflush(stdscr, true) // Prevent flush
@epohs
epohs / add-torrent.py
Last active April 9, 2018 16:46
Add a torrent and a label via one command line script
#!/usr/bin/env python
# USAGE:
#
# ./add-torrent.py -t "https://downloads.raspberrypi.org/raspbian_lite_latest.torrent" -l "app"
# ./add-torrent.py -t "magnet:?xt=urn:btih:3b17032b53cf45fbf6861a7d32f9af5dcae2709b&dn=ipMagnet+Tracking+Link&tr=http%3A%2F%2Fipmagnet.services.cbcdn.com%3A80%2F" -l "app"