Skip to content

Instantly share code, notes, and snippets.

@reisenmachtfreude
reisenmachtfreude / debian11_install_geth.sh
Last active September 21, 2024 18:27
Install geth on Debian 11 bullseye using ubuntu ppa
su # Run the following commands as root
echo "deb http://ppa.launchpad.net/ethereum/ethereum/ubuntu bionic main
deb-src http://ppa.launchpad.net/ethereum/ethereum/ubuntu bionic main" > /etc/apt/sources.list.d/ethereum-bioinc.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 2A518C819BE37D2C2031944D1C52189C923F6CA9
apt-get update
apt-get install ethereum
# Taken from https://linuxconfig.org/ethereum-mining-on-ubuntu-18-04-and-debian
# GETH Manual does not explicitly mention Debian and Ubuntu method is failing https://geth.ethereum.org/docs/install-and-build/installing-geth
@christiangenco
christiangenco / ViewController.swift
Created December 30, 2020 02:13
Minimal macOS Swift app to show webcam video in a custom NSView
import Cocoa
import AVFoundation
// inspiration: https://www.youtube.com/watch?v=1_PUdhLQsZQ
class ViewController: NSViewController {
@IBOutlet weak var videoView: NSView!
private var cameraSession = AVCaptureSession()
private var camera: AVCaptureDevice!
@cutiful
cutiful / mastodon-ip.md
Last active March 21, 2024 04:00
Detecting the real IP of a Cloudflare'd Mastodon instance

Detecting the real IP of a Cloudflare'd Mastodon instance

NB: This will not work for instances that proxy outgoing requests!

Reading the docs

I wanted to find a way to detect the real IP address of a Mastodon/Pleroma/Misskey/etc instance hosted behind Cloudflare. How to do that? Well, it's federated, which means I can probably get it to send a request to a server of mine! And how to do that? I tried reading the ActivityPub spec. The following caught my attention:

Servers should not trust client submitted content, and federated servers also should not trust content received from a server other than the content's origin without some form of verification.

@banjun
banjun / BlackHoleAVCaptureAudioPreviewOutput.swift
Created April 18, 2020 17:50
Set AVCaptureSession output to BlackHole or another arbitrary device by an output device name
private let audioOutput: AVCaptureAudioPreviewOutput = {
let audioOutput = AVCaptureAudioPreviewOutput()
audioOutput.volume = UserDefaults.standard.volume
struct Device {
var name: String?
var uid: String?
}
var devicesProperty = AudioObjectPropertyAddress(mSelector: kAudioHardwarePropertyDevices, mScope: kAudioDevicePropertyScopeOutput, mElement: kAudioObjectPropertyElementWildcard)
var devicesSize: UInt32 = 0
@jsharp83
jsharp83 / CameraManager.swift
Last active August 31, 2024 23:42
Basic camera code using AVCaptureSession in iOS
import Foundation
import AVFoundation
@objc
protocol CameraCaptureDelegate: class {
func captureVideoOutput(sampleBuffer: CMSampleBuffer)
@objc optional func captureAudioOutput(sampleBuffer: CMSampleBuffer)
}
class CameraManager: NSObject {
@cellularmitosis
cellularmitosis / EmojiPointersDemo.swift
Created August 15, 2018 18:11
Representing pointer values as emoji can be useful for "visually" debugging certain issues, like cell reuse, etc.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
@pholas
pholas / .gitignore
Created November 7, 2016 08:42
.gitignore for Xcode 8 and Swift 3
## OS X files
.DS_Store
.DS_Store?
.Trashes
.Spotlight-V100
*.swp
## Xcode build files
DerivedData/
build/
@iandundas
iandundas / String+emoji.swift
Last active April 23, 2022 16:30
Random Emoji
// Returns a random Emoji 🌿
extension String{
func randomEmoji()->String{
let range = 0x1F601...0x1F64F
let ascii = range.startIndex + Int(arc4random_uniform(UInt32(range.count)))
let emoji = String(UnicodeScalar(ascii))
return emoji
}
}
@mwaterfall
mwaterfall / StringExtensionHTML.swift
Last active May 27, 2024 04:36
Decoding HTML Entities in Swift
// Very slightly adapted from http://stackoverflow.com/a/30141700/106244
// 99.99% Credit to Martin R!
// Mapping from XML/HTML character entity reference to character
// From http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
private let characterEntities : [String: Character] = [
// XML predefined entities:
""" : "\"",
"&" : "&",
@edwardmp
edwardmp / gist:a0ffb3ace02ce4392b26
Created June 13, 2015 15:58
Working example of accepting self-signed SSL certificate in Swift
import UIKit
import Foundation
class ViewController: UIViewController, NSURLSessionDelegate {
override func viewDidLoad() {
super.viewDidLoad()
httpGet(NSMutableURLRequest(URL: NSURL(string: "https://example.com")!))
}