Skip to content

Instantly share code, notes, and snippets.

@algal
algal / websitescreenshot.md
Last active August 11, 2024 18:37
Taking website screenshots, in Chrome or Safari, including simulating iPhones

Taking website screenshots

These are instructions for taking screenshots of an entire webpage, not just the part of the webpage visible in the browser.

Website Screenshots in Safari

This requires Safari 11.3, which comes on macOS 10.3.4.

  1. Open the website in Safari
  2. If needed, go Safari > Preferences > Advanced > Show Develop Menu in Menu Bar
@algal
algal / gist:0f047de3493b34a21026336ba0bf90fd
Created March 14, 2018 03:04
ClojureAgentInSwift.swift
import Foundation
/*
Same API as Clojure's agents, but sadly not based on a lockless compare-and-swap operation since Swift doesn not provide one yet.
*/
class Agent<T>
{
/**
Returns an array of vertex positions.
- precondition: the geoemetry must have vertices which are 3-vectors with floating point component values
*/
fileprivate func vertices(source:SCNGeometrySource) -> [SCNVector3]
{
precondition(source.usesFloatComponents == true, "I can only handle three-vectors whose components are floating-point values, i.e., floats or doubles")
precondition(source.componentsPerVector == 3, "I can only be used for three vectors")
/*:
Paste this into Swift Playgrounds on an iPad to see how
modifying a label's frame affects its intrinsicContentSize.
As near as I can tell, frame currently does not affect
intrinsicContentSize.
At least I am sure it did not used to affect it.

Setting up a Jupyter server

These notes describe how to install and configure a secured Jupyter server directly onto Ubuntu 16.04.

Warning: this might be stupid. In 2017, it might be wiser just to grab a docker image, since some of these look extremely well-packaged. In my view, the advantage of docker is that someone else does the packaging, while docker itself provides cross-platform portability, rudimentary process supervision, and perhaps a simpler model than your OS's package manager. It is easy to know what is installed, how to uninstall it, and where its boundaries are. The disadvantage of docker is that you need to understand docker possibly in addition to understanding some Unix fundamentals.

Setup LetsEncrypt certs if needed

Install LetsEncrypt

@algal
algal / emacs-open-new-window.sh
Created October 24, 2017 04:41
emacs-open-new-window.sh
#!/bin/sh
emacsclient -n -e "(find-file-other-frame \"$1\")"
# For this script to work, you must already have started
# an emacs instance and started its server. You can do
# that by adding some elisp like the following into
# your .emacs file:
#
# (require 'server)
# (server-mode 1)
@algal
algal / CGColorGenerator.swift
Created August 8, 2017 16:05
Generate CGColors to match UIColors
//: Known-Good: Version 9.0 beta 5 (9M202q)
//: Playground - noun: a place where people can play
import UIKit
//: This playground is for generating code to define CGColors to match UIColors
@algal
algal / CharSet+ShellSafe.swift
Last active August 8, 2017 00:15
Shell-safe characters
// known-good: Xcode 8.3.3
/*
This shell script outputs which characters are special and need escaping in bash or sh:
#!/bin/bash
special=$'`!@#$%^&*()-_+={}|[]\\;\':",.<>?/ '
for ((i=0; i < ${#special}; i++)); do
char="${special:i:1}"
printf -v q_char '%q' "$char"
@algal
algal / CGRect+Codable.swift
Created July 10, 2017 21:58
CGRect Codable implementation
// known-good: Swift 4, in Xcode Version 9.0 beta 2 (9M137d)
// will be unnecessary once the language can auto-synthesize for this case, or
// when Apple's ships a Codable implementation for CoreGraphics struct types.
extension CGSize : Codable {
enum CodingKeys: String, CodingKey {
case width
case height
}
@algal
algal / sendSynchronousRequest.swift
Last active April 25, 2017 03:20
Synchronous HTTP request in
// known-good: 8.3.2, Swift 3
/**
Sometimes you just want to launch a synchronous HTTP request for some JSON, damnit.
Other approaches here: https://github.com/algal/SynchronousDownloadPlayground
*/
extension URLSession {
func sendSynchronousRequest(_ request:URLRequest,