Skip to content

Instantly share code, notes, and snippets.

View ddrscott's full-sized avatar

Scott Pierce ddrscott

View GitHub Profile
@ddrscott
ddrscott / cf-gpt.sh
Created November 22, 2023 19:02
Cloudflare AI inference API
#!/bin/sh
# message can come from script args or environment
message=${message:-"${*}"}
model=${model:-"@cf/mistral/mistral-7b-instruct-v0.1"}
system=${system:-"You are a consice AI assistant. You help the user the best you can. If you don't know something, you admin it and ask clarifying questions. Use markdown as needed."}
post_data=$(cat <<JSON
{"messages":[{"role":"system","content":"${system}"},{"role":"user","content":"${message}"}],"max_tokens":10240,"stream":true}
JSON
)
@sanp
sanp / 2pa.md
Last active August 23, 2019 18:51

Second Price Auctions

Overview

  • Second price auctions (2PA) are a type of auction where the highest bidder pays the second highest bid
  • In contrast to first price auctions (FPA), where the highest bidder pays her own bid

In this talk, going to go over

  • Why 2PA work better than FPA
@a7v8x
a7v8x / graphql_introspection_query.graphql
Last active November 5, 2023 12:36
GraphQL introspection query - for fetching the whole schema (from GraphiQL IDE) for https://atheros.ai/blog/graphql-introspection-and-introspection-queries
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
types {
...FullType
}
directives {
name
description
@BrianMehrman
BrianMehrman / prettySQL.py
Last active July 5, 2018 20:10
pretty print your SQL
#!/usr/bin/env python
import argparse
import sys
import sqlparse
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import TerminalTrueColorFormatter
def prettyPrint(raw_sql):
@ddrscott
ddrscott / push_it.mp3
Last active April 4, 2017 10:31
"Push It" by Salt'N Pepa circa 1986
@ddrscott
ddrscott / grade_school.rb
Last active February 9, 2018 22:10
Grade school using funky lambda
alias λ lambda
sadd = λ {|ns, a| [*ns, a].sort }
hsort = λ {|h| Hash[h.sort] }
hadd = λ {|h, n, g| h.merge(g => sadd.(h[g], n)) }
school = λ {|gs| School.new(gs) }
School = Struct.new(:gs) do
define_method :add, λ {|n, g| (school . (hsort . (hadd . (to_hash, n, g)))) }
define_method :to_hash, λ {| | gs || {} }
@ddrscott
ddrscott / pry_psql.rb
Last active August 19, 2021 19:17
Pry command to execute SQL as text or Rails scopes
# Load this file in your `.pryrc`
#
# load 'path/to/pry_sql.rb'
#
# See how to use this by running: `psql --help`
# Originally created for Rails 3.
# Updated to Rails 6
module Rails
class DBConsole
APP_PATH = Rails.root.join('config', 'application')
@sanp
sanp / ssh_tunnelling.md
Last active February 21, 2017 21:43
Lightening Talk for Centro Tech Team on 2/15/17

SSH Tunneling

Problem

You want to query a DB and get a result set, but you don't have access to that DB directly from your localhost.

  • Bad solution A: Cry
  • Bad solution B: Ask someone who does have access to run your query for you
  • Bad solution C: ssh into a box that has access, then psql into the DB
@ddrscott
ddrscott / .screenrc
Created December 1, 2016 20:09
screenrc with pretty colors
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'
@romainl
romainl / Vim_pushing_built-in_features_beyond_their_limits.markdown
Last active September 19, 2023 08:16
Vim: pushing built-in features beyond their limits

Vim: pushing built-in features beyond their limits

The situation

Searching can be an efficient way to navigate the current buffer.

The first search commands we learn are usually / and ?. These are seriously cool, especially with the incsearch option enabled which lets us keep typing to refine our search pattern. / and ? really shine when all we want is to jump to something we already have our eyeballs on but they are not fit for every situation:

  • when we want to search something that's not directly there, those two commands can make us lose context very quickly,
  • when we need to compare the matches.