Skip to content

Instantly share code, notes, and snippets.

@aaronvegh
aaronvegh / test.go
Last active December 2, 2020 19:17
De-Escalation & Restart Server
package main
import (
"fmt"
"github.com/creack/golisten"
"log"
"net/http"
"os"
"os/exec"
"os/user"
#!/usr/bin/env ruby
require 'net/http'
require 'date'
destination_folder = "/path/to/your/crosssword/folder"
# go back a month and download everything we don't have
starting_date = Date.today - 30
(starting_date .. starting_date + 30).each do |d|
@aaronvegh
aaronvegh / deploy-swift-vapor-ubuntu.md
Last active January 15, 2019 13:55
Deploy Swift Vapor 3 Binary to Ubuntu

My goal was to publish a binary application written in Swift 4.2 for Vapor 3 to a server running Ubuntu, and have it run like any other server app.

The intended target is an LXD container, though this should work just as well on any Ubuntu VM or other private server from Linode or Digital Ocean.

Here's how I did it.

  1. Install Ubuntu 18.04 (includes libicu v 60)
  2. apt install libatomic1
  3. Download Swift for Ubuntu 18.04 (https://swift.org/builds/swift-4.2.1-release/ubuntu1804/swift-4.2.1-RELEASE/swift-4.2.1-RELEASE-ubuntu18.04.tar.gz)
  4. archive dynamic libs from swift release /usr/lib/lib* files
@aaronvegh
aaronvegh / crossword_getter.rb
Created February 10, 2018 18:47
Fetch the Newsday Daily Crossword
#!/usr/bin/env ruby
require 'net/http'
require 'date'
destination_folder = "/absolute/path/to/destination"
# go back a month and download everything we don't have
starting_date = Date.today - 30
(starting_date .. starting_date + 30).each do |d|
@aaronvegh
aaronvegh / splitBy.swift
Last active April 24, 2017 20:22 — forked from shsteven/splitBy.swift
Swift: split array by chunks of given size
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
extension Array {
func splitBy(subSize: Int) -> [[Element]] {
return stride(from: 0, to: self.count, by: subSize).map { startIndex in
if let endIndex = self.index(startIndex, offsetBy: subSize, limitedBy: self.count) {
return Array(self[startIndex ..< endIndex])
}
return Array()
}
{
"enjoyWatchingPugs": true,
"favoritePugName": "The Grand Lord Earl McPugwitch of Puggington, Esquire"
}
@aaronvegh
aaronvegh / gist:9add42444aaaabec7283
Last active December 14, 2015 18:07
Ranking Things in Groups of Five

I have an array of colour schemes. Each scheme is five UIColor objects.

I want to give view-type things a colour automatically. If you have more than five items, I want to cycle around and start using colours over again.

So views 1-5 will have the five colours in the scheme. But view 6 should have the same colour as view 1.

This is the math I'm using to solve this problem:

let modulo = colors.count + 1 / 5
var thisTimer = NSTimer.every(1, {
self.currentCountdown = self.currentCountdown! - 1
// do stuff here...
if self.currentCountdown == 0 {
// do other stuff here...
thisTimer.invalidate()
}
})
//
// WWTemplateShapeCircle.swift
// WordWright
//
// Created by Aaron Vegh on 2015-10-08.
// Copyright © 2015 Aaron Vegh. All rights reserved.
//
import UIKit
import UIKit
enum ShapeType {
case Circle
case Line
case Polygon
}
protocol WWTemplateShape {