Skip to content

Instantly share code, notes, and snippets.

View gbertb's full-sized avatar

Gilbert Bagaoisan gbertb

  • San Francisco, CA
View GitHub Profile
@gbertb
gbertb / macOS Internals.md
Created May 8, 2023 16:12 — forked from kconner/macOS Internals.md
macOS Internals

macOS Internals

Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.

Starting Points

How to use this gist

You've got two main options:

@gbertb
gbertb / dispatch_openai_requests.py
Created May 3, 2023 04:19 — forked from neubig/dispatch_openai_requests.py
A simple script to get results from the OpenAI Asynchronous API
import openai
import asyncio
from typing import Any
async def dispatch_openai_requests(
messages_list: list[list[dict[str,Any]]],
model: str,
temperature: float,
max_tokens: int,
top_p: float,
@gbertb
gbertb / middleware.ts
Created April 23, 2023 03:25 — forked from perkinsjr/middleware.ts
Using Clerk with Upstash for Middleware rate limiting and API Protection
import { getAuth, withClerkMiddleware } from "@clerk/nextjs/server";
import { NextResponse, NextFetchEvent } from "next/server";
import type { NextRequest } from "next/server";
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";
// Add public paths for Clerk to handle.
const publicPaths = ["/", "/sign-in*", "/sign-up*", "/api/blocked"];
// set your rate limit.
@gbertb
gbertb / promptlayer.js
Created March 26, 2023 20:37
example promptlayer call
var requestStartTime = Date.now()
const stream = new ReadableStream({
async start(controller) {
const onParse = (event: ParsedEvent | ReconnectInterval) => {
if (event.type === "event") {
const data = event.data;
if (data === "[DONE]") {
controller.close();
@gbertb
gbertb / list.md
Created November 18, 2020 00:12 — forked from ih2502mk/list.md
Quantopian Lectures Saved
@gbertb
gbertb / twittermute.txt
Created January 25, 2020 19:03 — forked from IanColdwater/twittermute.txt
Here are some terms to mute on Twitter to clean your timeline up a bit.
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet
@gbertb
gbertb / playAudio.swift
Created November 5, 2018 02:54
Play Audio after completing quiz
func playAudio() {
do {
if let fileURL = Bundle.main.path(forResource: "Game Show Win", ofType: "wav") {
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileURL))
audioPlayer?.volume = 0.4
} else {
print("No file with specified name exists")
}
} catch let error {
@gbertb
gbertb / fadeLeft.swift
Created October 26, 2018 20:41
custom fade view transition
// RoommateMatchQuestionViewController.swift
let vc = RoommateMatchQuestionViewController.newInstance()
vc.viewModel = self.viewModel.viewModelForNextQuestion()
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionFade
@gbertb
gbertb / UIView+Hierarchy.swift
Created June 16, 2018 01:09 — forked from myell0w/UIView+Hierarchy.swift
Traverse View Hierarchy Upwards
extension UIView {
func findFirstSuperview<T>(ofClass viewClass: T.Type, where predicate: (T) -> Bool) -> T? where T: UIView {
var view: UIView? = self
while view != nil {
if let typedView = view as? T, predicate(typedView) {
break
}
view = view?.superview
}
@gbertb
gbertb / branch.html
Last active February 12, 2018 21:13
Phone number validation with branch
<html>
<head>
</head>
<body>
<p class="send-instructions">Enter your number and we'll send you a link to download the app</p>
<form id="enter-phone-number" onsubmit="sendBranchLink(this); return false;" class="row">
<div class="large-12 columns">
<div class="row collapse">
<div class="small-7 medium-10 columns">
<input id="phone" type="tel" pattern="^\(?\+?[\d\(\-\s\)]+$" class="input-group-field" placeholder="(408) 219-0093" data-placeholder="">