Skip to content

Instantly share code, notes, and snippets.

View yesmar's full-sized avatar
💭
Another Fine Product From The Nonsense Factory

ɹɐɯsǝʎ yesmar

💭
Another Fine Product From The Nonsense Factory
  • /dev/funk
View GitHub Profile
@yesmar
yesmar / aapl_slurp.rb
Last active January 27, 2018 01:01
Bulk downloader for Apple open source projects
#!/usr/bin/env ruby
# aapl_slurp.rb: downloader for Apple open source projects
# Copyright © 2017, Ramsey Dow. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause
# mkdir /tmp/macOS-1013 && pushd !#:1
# curl -#LO https://opensource.apple.com/plist/macos-1013.plist
# SSL_CERT_FILE=$CURL_CA_BUNDLE ruby /path/to/aapl_slurp.rb macos-1013.plist
@yesmar
yesmar / dga.rb
Last active January 27, 2018 01:03
Domain Generation Algorithm inspired by Ranbyus (by way of Mirai)
#!/usr/bin/env ruby
# dga.rb: domain generation algorithm inspired by Ranbyus (by way of Mirai)
# Usage: ruby dga.rb [n]
# where n is an integer representing the number of days to span.
# -n indicates previous days, 0 and 1 indicate today, and 2+ indicates tomorrow and so on.
module DNS
LETTERS='abcdefghijklmnopqrstuvwxyz'.scan(/./)
@yesmar
yesmar / runWithDebugger.js
Created January 26, 2018 23:15
Run code through the Chrome debugger with an optional args parameter
(function() {
'use strict';
function runWithDebugger(f, args) {
if (typeof f !== 'function') { throw 'f must be a function' }
// The apply() method treats unspecified args or null or undefined args as 'no args'.
if (args === undefined || typeof args === 'object' && (args === null || Array.isArray(args))) {
debugger;
f.apply(null, args);
} else {
@yesmar
yesmar / ua.js
Last active January 27, 2018 01:07
Generate random User Agent
const fs = require('fs');
const ua = fs.readFileSync('ua.txt').toString().split("\n"),
agent = ua[Math.floor(Math.random()*ua.length)];
console.log(agent);
@yesmar
yesmar / cvss.js
Last active January 27, 2018 01:04
Compute CVSSv3 score from vector
// cvss.js: Compute CVSSv3 score from vector.
// Copyright © 2018, Ramsey Dow. All rights reserved.
// SPDX-License-Identifier: BSD-2-Clause
// Developed under the influence of Rick and Morty. TINY RICK!
const vectorToObject = (string) => {
const metrics = {};
if (isEmpty(string)) throw 'Empty string';
const scratch = string.split('/');
@yesmar
yesmar / precip.bash
Created January 26, 2018 23:44
Mainly it snows, but sometimes it rains knives…
#!/bin/bash
case $((RANDOM % 4)) in
1) precip=🔪 ;;
*) precip=❄️ ;;
esac
lines=$(tput lines)
columns=$(tput cols)
@yesmar
yesmar / constructPathname.swift
Created January 30, 2018 21:19
Standardize construction of pathnames with extensions when multiple periods are involved
import Foundation
import PlaygroundSupport
func constructPathname(pathname: URL, name: String, ext: String) -> URL {
let n = name.hasSuffix(".") ? String(name.dropLast()) : name
let x = ext.hasPrefix(".") ? String(ext.dropFirst()) : ext
return pathname.appendingPathComponent("\(n).\(x)")
}
print(constructPathname(pathname: playgroundSharedDataDirectory, name: "Tea, Inc.", ext: ".json"))
@yesmar
yesmar / rootcheck.bash
Created February 2, 2018 03:19
Ensure script is running as root
#!/bin/bash
((EUID != 0)) && printf >&2 "This script should be run as root\\n" && exit 1
@yesmar
yesmar / atv_vidslurp.rb
Created February 10, 2018 19:40
Pull down Apple's HD screensaver vids from Phobos
#!/usr/bin/env ruby
# atv_vidslurp.rb, 20161216 yesmar@gmail.com
# Pull down Apple's HD screensaver vids from Phobos.
require 'net/http'
require 'json'
PHOBOS_URL='http://a1.phobos.apple.com/us/r1000/000/Features/atv/AutumnResources/videos/entries.json'
@yesmar
yesmar / fusbsd.bash
Created February 12, 2018 06:30
Create bootable USB installer for FreeBSD
#!/bin/bash
mkdir -p /tmp/freebsd && pushd !#:2
curl -#LO https://www.freebsd.org/releases/11.1R/CHECKSUM.SHA512-FreeBSD-11.1-RELEASE-amd64.asc
curl -#LO https://download.freebsd.org/ftp/releases/amd64/amd64/ISO-IMAGES/11.1/FreeBSD-11.1-RELEASE-amd64-memstick.img.xz
mkdir -p keyring && chmod 0700 !#:2
gpg --homedir=keyring --keyserver keyserver.ubuntu.com --recv-keys 8D12403C2E6CAB086CF64DA3031458A5478FE293
gpg --homedir=keyring --verify CHECKSUM.SHA512-FreeBSD-11.1-RELEASE-amd64.asc
grep FreeBSD-11.1-RELEASE-amd64-memstick.img.xz \
CHECKSUM.SHA512-FreeBSD-11.1-RELEASE-amd64.asc \
| awk '{ gsub("[()]",""); print $4 " " $2 }' \