Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
int main(int argc, char **argv) {
printf("Hello world!");
return 0;
}
@vivekhaldar
vivekhaldar / church.py
Created April 21, 2012 17:11
Church numerals in Python
#! /usr/bin/python
#
# Church numerals in Python.
# See http://en.wikipedia.org/wiki/Church_encoding
#
# Vivek Haldar <vh@vivekhaldar.com>
#
# https://gist.github.com/2438498
zero = lambda f: lambda x: x
@vivekhaldar
vivekhaldar / church.js
Created March 4, 2016 21:11
Church numerals in ES6.
//#!/usr/bin/env node --harmony
/*jshint esversion: 6 */
'use strict';
// Church numerals in ES6.
// c.f. https://en.wikipedia.org/wiki/Church_encoding
// Zero is the identity function.
let zero = (f => x => x);
#!/usr/bin/env python
import math
import sys
from moviepy.editor import AudioClip, VideoFileClip, concatenate_videoclips
# Get average RGB of part of a frame. Frame is H * W * 3 (rgb)
# Assumes x1 < x2, y1 < y2
@vivekhaldar
vivekhaldar / gist:e700f385dde7ba8d6b0a623000f74778
Created February 12, 2023 15:57
devenv error for Python setup with Poetry
devenv.sh:
{ pkgs, ... }:
{
env.GREET = "Python-based dev env for copy-pics";
languages.python = {
enable = true;
poetry.enable = true;
@vivekhaldar
vivekhaldar / chat.py
Created March 6, 2023 14:46
Simple Python script to invoke ChatGPT API.
#!/usr/bin/env python3
#
# Takes a chat transcript (for ChatGPT) on stdin, calls the OpenAI
# ChatGPT API, and prints the response on stdout.
#
# Your OpenAI API key must be set in the environment variable
# OPENAI_API_KEY.
#
# Logs are written to ~/chat.log.
;; emacs-gpt.el -- Control Emacs via ChatGPT
;;
;; Basic idea: take natural language input from user, ask ChatGPT for
;; corresponding elisp, run it.
(defun mark-between-assistant-and-user ()
"Mark the region between \"%assistant%\" and \"%user%\", not including those strings."
(interactive)
(goto-char (point-min))
import os
from time import sleep
from openai import OpenAI
client = OpenAI(
# defaults to
api_key=os.environ.get("OPENAI_API_KEY"),
)
# Step 1: Create an Assistant
@vivekhaldar
vivekhaldar / chat-gpt.el
Last active December 17, 2023 15:51
Emacs lisp to call out to Python script that calls ChatGPT API + Markdown derived mode for the chat transcripts.
;; Emacs Lisp wrapper around Python scripts for ChatGPT.
;;
;; Basic idea is to send buffer as stdin to Python script.
(defvar gpt-script "/Users/haldar/haskell/gpt_turbo/chat.py")
(defun vh/invoke-chat ()
"Send contents of current buffer as stdin to command, then append output to current buffer."
(interactive)
(let*
@vivekhaldar
vivekhaldar / cut_silence.py
Last active January 19, 2024 14:00
Python script to cut out silent parts from a video. Uses moviepy.
#!/usr/bin/env python
#
# Based on a script by Donald Feury
# https://gitlab.com/dak425/scripts/-/blob/master/trim_silenceV2
# https://youtu.be/ak52RXKfDw8
import math
import sys
import subprocess
import os