Skip to content

Instantly share code, notes, and snippets.

View rubencodes's full-sized avatar

Ruben Martinez Jr. rubencodes

View GitHub Profile
@rubencodes
rubencodes / console.log in Swift
Last active November 13, 2015 06:01
Force of habit: I keep trying to use console.log in Swift, to no avail. No longer!
class console {
class func log(arg : Any) {
print(arg)
}
}
console.log("Hello World!")
@rubencodes
rubencodes / .bash_rc
Created September 15, 2016 07:19
Google Search CLI
#Begin GoogleSearch CLI for Mac
function google() {
if [ $1 = "--images" ]; then
open https://google.com/search?tbm=isch\&q="$2"
elif [ $1 = "--news" ]; then
open https://google.com/search?tbm=nws\&q="$2"
else
open https://google.com/search?q="$1"
fi
}
@rubencodes
rubencodes / google.js
Last active May 10, 2018 15:13
Find valid .google domains
// I ran this with:
// while true; do node ~/Desktop/google.js --max_old_space_size=4096 --optimize_for_size --max_executable_size=4096 --stack_size=4096 && break; done
// This will run the script with 4GB allocated memory, and auto-restart if it crashes (happens sometimes due to out of memory).
const https = require('https');
const fs = require('fs');
// File storage between runs.
const validStorage = '/Users/ruben/Desktop/validURLs.txt';
const attemptsStorage = '/Users/ruben/Desktop/attempts.txt';
@rubencodes
rubencodes / vaccine-finder.js
Last active March 30, 2021 14:39
Check for appointments on the NY State vaccination website. https://am-i-eligible.covid19vaccine.health.ny.gov/Public/providers
/*
* This script will automatically play a sound and trigger an alert when it finds available appointments
* on the New York State vaccine finder website. https://am-i-eligible.covid19vaccine.health.ny.gov/Public/providers
* It can be run by pasting it into the Chrome console at the above URL.
*
* NOTE: You must meet certain eligibility criteria to qualify for a vaccine.
*/
// Map of all providers - use to populate `providersToCheck` field.
const Providers = {
@rubencodes
rubencodes / curry.ts
Created November 24, 2021 14:32
TypeScript Currying
type AnyArray = any[];
type AnyArrayWithItems = [any, ...any];
type AnyFunction<Arguments extends any[] = any[]> = (...args: Arguments) => any;
// The type of the first item in an array.
// Input: `[1, 2, 3]`
// Output: `1`
type Head<SomeArray extends AnyArray> = SomeArray extends AnyArrayWithItems
? SomeArray[0]
: never;
@rubencodes
rubencodes / DataStorage.swift
Created December 1, 2022 21:43
Property wrapper for storing any `Codable` data structure into a `UserDefaults` store.
import SwiftUI
@propertyWrapper public struct DataStorage<Value: Codable>: DynamicProperty {
// MARK: - Private Properties
private var defaultValue: Value
private var storageKey: String
private var store: UserDefaults
private var data: AppStorage<Data?>
@rubencodes
rubencodes / View+Extension.swift
Created June 7, 2023 16:19
Conditional Modifier Extension
/* Example Usage
struct ContentView: View {
let isRounded: Bool
var body: some View {
Color.blue
.conditionalModifier { view in
if isRounded {
view.clipShape(Circle())
@rubencodes
rubencodes / SpacingDemo_Previews.swift
Last active February 28, 2024 14:43
SwiftUI Spacing Demo
@available(iOS 16.0, *)
struct SpacingDemo_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
Form {
Group {
Section {
HStack {
Spacer()
Rectangle().fill(.blue)