Skip to content

Instantly share code, notes, and snippets.

View sadasant's full-sized avatar
👁️

Daniel Rodríguez sadasant

👁️
View GitHub Profile
@sadasant
sadasant / _README.md
Last active August 30, 2023 17:33
Bash function for piping command outputs to OpenAI's GPT-4 model

This gpt() function reads input from the command line and then sends a formatted JSON object to the OpenAI API for the GPT-4 model. It properly escapes special characters and checks for the .env file containing the OpenAI API key.

Usage:

  • Load the function into your environment: source gpt.sh.
  • Make sure to have an .env file in the current directory with the OPENAI_API_KEY.
  • Pipe anything itno it, and also add a prompt, example:
git diff main | gpt "As a programmer, review this diff. Provide feedback only if necessary. Be brief"
@sadasant
sadasant / index.ts
Created June 26, 2020 19:06 — forked from willmtemple/index.ts
magic typescript function that returns its arguments' AST
// This uses my modified version of typescript from my branch github.com/willmtemple/typescript#fucking-parser
import * as ts from "typescript/built/local/typescript";
import * as fs from "fs";
import * as os from "os";
import { promisify } from "util";
const readFile = promisify(fs.readFile);
@sadasant
sadasant / computer_tips.md
Last active January 20, 2020 15:29
Computer tips to Jen Gentleman

Computer tips to Jen Gentleman.

For this Twitter thread: https://twitter.com/JenMsft/status/1218526323271823360

I've taken all of these from information I've found publicly available on the interner over the years. I haven't kept all of the sources.

I thought on adding more than bash-related stuff, but I ended up unconvinced. I hope some of this can be useful!

Index

Keybase proof

I hereby claim:

  • I am sadasant on github.
  • I am sadasant (https://keybase.io/sadasant) on keybase.
  • I have a public key ASDfYbR_Nx35Pf2hogjNpqwWYCLmlG-xy80sToPxSMk94go

To claim this, I am signing this object:

const S = require('sanctuary')
let objectMatches = object => S.allPass(
S.map(([k, v]) =>
S.pipe([
S.prop(k),
S.is(Function, v) ?
v :
S.is(RegExp, v) ?
S.test(v) :
@sadasant
sadasant / RunAProxyOnAmazonEC2VPC.md
Created April 14, 2017 13:35 — forked from webinista/RunAProxyOnAmazonEC2VPC.md
Create a proxy server on an Amazon EC2 (VPC) instance

This will create a proxy server in whatever your availability zone your VPC is in. For me, that's us-east-1b. For you, that may be something different. Steps 10+ should more or less work regardless of your provider since those steps cover the setup and configuration of TinyProxy.

  1. Click the Launch Instance button.
  2. Choose Ubuntu Server 14.04 LTS (HVM), SSD Volume Type. This isn't strictly necessary. If you choose another OS, check its documentation for how to install new packages.
  3. On the Choose an Instance Type screen, select t2.micro. It's Free Tier eligible.
  4. Click the Next: ... buttons until you reach the Configure Security Group screen.
    • You may wish to reduce the amount of storage on the Add Storage screen. This is optional.
    • You may wish to add a tag on the Tag Instance screen. This is also optional.
  5. On the Configure Security Group screen:
  • Select Create a new security group.
@sadasant
sadasant / foldWhile.mkd
Last active August 28, 2021 10:27
Recursive fold takeWhile (as in haskell)

Recursive fold takeWhile (as in haskell). Lazy evaluated!

  • Iterates depth-first every element of a nested data structure given as obj.
  • Runs only while the iterator fn returns true.
  • The fn iterator receives:
    • An accumulator, that by default is an array, but that can be defined as anything else in the third parameter given to foldWhile.
    • The next value iterated.
@sadasant
sadasant / DurandalHistoryCheckUrl
Created January 25, 2017 21:06
Duranda's History checkUrl fix
/**
* Checks the current URL to see if it has changed, and if it has, calls `loadUrl`, normalizing across the hidden iframe.
* @method checkUrl
* @return {boolean} Returns true/false from loading the url.
*/
function cleanFragment(s) {
return s
.replace(/%7E/g, "~")
.replace(/%21/g, "!")
.replace(/%2A/g, "*")
@sadasant
sadasant / index.html
Created November 23, 2016 15:19 — forked from anonymous/index.html
Tic-Tac-Toe// source https://jsbin.com/qototad
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1">
<title>Tic-Tac-Toe</title>
</head>
<body>
<div class='wrapper'>
node E0003-Sieve.js
<--- Last few GCs --->
7126 ms: Mark-sweep 1096.1 (1134.7) -> 659.1 (697.6) MB, 181.5 / 0 ms [allocation failure] [GC in old space requested].
7327 ms: Mark-sweep 659.1 (697.6) -> 658.8 (697.6) MB, 201.1 / 0 ms [allocation failure] [GC in old space requested].
7509 ms: Mark-sweep 658.8 (697.6) -> 658.8 (697.6) MB, 181.4 / 0 ms [last resort gc].
7711 ms: Mark-sweep 658.8 (697.6) -> 658.8 (697.6) MB, 202.1 / 0 ms [last resort gc].