Skip to content

Instantly share code, notes, and snippets.

View shanecowherd's full-sized avatar

Shane Cowherd shanecowherd

  • Cowherd.com, Making Blocks, PBSCO, Bulb, BombBomb, Echo1612
  • Colorado Springs
  • 12:59 (UTC -06:00)
View GitHub Profile
@shanecowherd
shanecowherd / NumberOfRecentCalls.swift
Created November 18, 2019 21:36
Number Of Recent Calls
//https://leetcode.com/problems/number-of-recent-calls/
// Tried for loop, etc. While loop was the best when dealing with 10000 requests
// Write a class RecentCounter to count recent requests.
// It has only one method: ping(int t), where t represents some time in milliseconds.
// Return the number of pings that have been made from 3000 milliseconds ago until now.
// Any ping with time in [t - 3000, t] will count, including the current ping.
// It is guaranteed that every call to ping uses a strictly larger value of t than before.
class RecentCounter {
@shanecowherd
shanecowherd / TwoSum.swift
Last active November 17, 2019 20:32
The typical two sum solution
// Create a dictionary with the key the index of each item in the array.
// The value is the difference between the array's value and the target.
// Now if we want to find the first solution that contains sum, just loop
// through the array and check the dictionary for other numbers who match the difference.
class Solution {
func twoSum(_ nums: [Int], _ target: Int) -> [Int] {
var dict = [Int:Int]()
for (i, val) in nums.enumerated() {
@shanecowherd
shanecowherd / CircularQueue.swift
Last active November 17, 2019 17:06
LeetCode 622. Design Circular Queue
//https://leetcode.com/problems/design-circular-queue/
//Passed
//Runtime: 104 ms, faster than 78.33% of Swift online submissions for Design Circular Queue.
//Memory Usage: 21.7 MB, less than 100.00% of Swift online submissions for Design Circular Queue.
class Item {
let value: Int
var next: Item?
var prev: Item?
@shanecowherd
shanecowherd / ExampleOperation.swift
Created November 12, 2019 23:06
Example Operation
let operationQueue = OperationQueue()
class ExampleOperation: Operation {
var delegate: SomeDelegate
var callbackDelegate: SomeCallbackDelegate
var success = false // I mark this when the operation has succeeded. Optional
init(delegate: SomeDelegate, callbackDelegate: SomeCallbackDelegate) {
self.delegate = delegate
self.callbackDelegate = callbackDelegate
@shanecowherd
shanecowherd / fileBiggerThan0KB.swift
Last active November 12, 2019 23:06
Check if a file is bigger than 0 KB
func fileBiggerThan0KB(path: String) -> Bool {
do {
var fileSize : UInt64 = 0
//return [FileAttributeKey : Any]
let attr = try FileManager.default.attributesOfItem(atPath: path)
fileSize = attr[FileAttributeKey.size] as! UInt64
//if you convert to NSDictionary, you can get file size old way as well.
let dict = attr as NSDictionary
@shanecowherd
shanecowherd / randmail.sh
Created October 11, 2019 18:44
Bash script to automate sending email from Mail.app using AppleScript. (For debugging)
#!/bin/bash
# Generate a random text email and send it to test@example.com
# Used for testing email apps when you need a lot of messages in a test account.
# Configure the script in this section.
NUMBER_OF_MESSAGES=10
WORDS_IN_MESSAGE=10
RECIPIENT=test@example.com
@shanecowherd
shanecowherd / AaronCodableBook.swift
Created September 11, 2019 01:22
Playing with Codable
import UIKit
struct JSONBook: Codable {
let book: Book
}
// MARK: - Book
struct Book: Codable {
let isbn, language, binding, publisher: String
let dimensions: String
@shanecowherd
shanecowherd / raspberry-pi-ffmpeg.swift
Created August 8, 2019 03:03
This file lets you record using ffmpeg on a raspberry pi, in swift!
//https://github.com/futurejones/Swift-Lite/
////Install
// curl -s https://packagecloud.io/install/repositories/swift-arm/swift-lite/script.deb.sh | sudo bash
// sudo apt-get install swift-lite-rpi
////Compile
// swift-lite-build raspberry-pi-ffmpeg.swift
////Run
// ./raspberry-pi-ffmpeg.swapp
@shanecowherd
shanecowherd / 7-19-2019 Blog.md
Created July 17, 2019 13:20
I am attempting to use Github Gist as a blog engine.

I'm a developer and I use GitHub all day, so naturally it would be awesome if I could use it for my blog. I've done the whole "roll your own" so many times I have lost count.

I started making my own blog/personal site back in 1997 and really fell in love using Microsoft Frontpage 1997. It was an awesome time to be on the internet. The .com bubble was starting and new web innovations were happening all over the place.

DHTML (Dynamic HTML) was my first foray into javascript. I remember using DHTML snippet websites and copy/pasting little javascript snippets into my source code. This allowed me to do some amazing things like…. On hover menus, simple fade animations, blinking text, and every other terrible myspace.com design abomination a teenager thought would be cool. Those were good times.

Later I started building sites with PHP and rebuilt my contentless website with every blog engine or cms I could try.

  • PHPNuke
  • e107