Skip to content

Instantly share code, notes, and snippets.

View cecilemuller's full-sized avatar

Cecile Muller cecilemuller

View GitHub Profile
@cecilemuller
cecilemuller / README.md
Last active October 20, 2023 09:42
Docker Compose Watch

Example for compose watch:

  • "watch" requires a "build" section
  • files created at runtime in the host get copied to the container
  • files deleted in the host aren't deleted in the container
  • files created in the container at build time aren't copied back to the host
  • files created in the container at runtime aren't copied back to the host
  • you'd still need a "volume" if the host must access files generated in the container
@cecilemuller
cecilemuller / extension.cjs
Last active August 15, 2023 01:25
VSCode: Open Webview Developer Tools automatically
/* eslint-env node */
"use strict";
const vscode = require("vscode");
function activate(context) {
const provider = new ExampleProvider(context.extensionUri);
context.subscriptions.push(
vscode.window.registerWebviewViewProvider("example", provider)
);
// ...
@cecilemuller
cecilemuller / commands.sh
Last active August 2, 2023 13:30
LLM on MacOS
brew install llm
llm install llm-llama-cpp
llm install llama-cpp-python
llm llama-cpp download-model https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q8_0.bin --alias llama2-7b --llama2-chat
llm llama-cpp download-model https://huggingface.co/TheBloke/Llama-2-13B-chat-GGML/resolve/main/llama-2-13b-chat.ggmlv3.q8_0.bin --alias llama2-13b --llama2-chat
llm llama-cpp download-model https://huggingface.co/TheBloke/Wizard-Vicuna-7B-Uncensored-GGML/resolve/main/Wizard-Vicuna-7B-Uncensored.ggmlv3.q4_0.bin --alias wizard-7b --alias autocomplete
llm -m llama2-7b 'Tell me a joke about a bird' --system 'You are funny'
llm -m llama2-13b 'Tell me a joke about a bird' --system 'You are funny'
@cecilemuller
cecilemuller / pwsh.mjs
Last active July 24, 2023 09:44
Run Powershell 7 commands in Node.js
import {exec} from "node:child_process";
/**
* Runs a Powershell 7 command.
* @param {string} command
* @returns {string}
* @example const stdout = await pwsh(`Write-Output "Hello World"`);
* @example const stdout = await pwsh(`Write-Output "Hello"; Write-Output "World"`);
*/
export async function pwsh(command) {
@cecilemuller
cecilemuller / parse-lnk.ps1
Last active July 23, 2023 12:16
PowerShell: parse .lnk file
$sh = New-Object -ComObject WScript.Shell; $sh.CreateShortcut("example.lnk").TargetPath
@cecilemuller
cecilemuller / noncopyable.swift
Created June 8, 2023 11:13
Swift 5.9: Noncopyable struct
// Noncopyable struct: passed by reference
// and only one variable can hold the reference.
struct User: ~Copyable {
var name: String
// Read-only
func read() {
print(self.name)
// self.name = "BBBBB" // Error: 'self' is immutable
}
@cecilemuller
cecilemuller / example.mjs
Created May 28, 2023 11:30
Download to file (Node 18)
import {createWriteStream} from "fs";
import {pipeline} from "stream/promises";
try {
const response = await fetch("https://github.githubassets.com/images/modules/logos_page/Octocat.png");
if (!response.ok) {
throw new Error(response.statusText);
} else {
await pipeline(response.body, createWriteStream("Octocat.png"));
}
@cecilemuller
cecilemuller / default_server.conf
Created May 13, 2023 21:42
Nginx: default_server fallback
# /etc/nginx/conf.d/default_server.conf
server {
server_name _;
listen 80 default_server;
listen [::]:80 default_server;
log_not_found off;
return 410;
}
server {
server_name _;
@cecilemuller
cecilemuller / UIView+distort.swift
Created April 9, 2023 07:43
Swift: distort a UIView to fit arbitrary corners
import UIKit
extension UIView {
/// Updates `anchorPoint`, `frame`, and `layer.transform` to fit arbitrary corners.
/// Based on https://stackoverflow.com/questions/9470493/transforming-a-rectangle-image-into-a-quadrilateral-using-a-catransform3d/39981054#39981054
func distort(topLeft tl: CGPoint, topRight tr: CGPoint, bottomLeft bl: CGPoint, bottomRight br: CGPoint) {
// Frame ----------------------------------------------------------- /
let xmin = min(tr.x, tl.x, bl.x, br.x)
let ymin = min(tr.y, tl.y, bl.y, br.y)
let xmax = max(tr.x, tl.x, bl.x, br.x)
@cecilemuller
cecilemuller / gist:3081372
Created July 10, 2012 05:37
PostgreSQL trigger: loop through the columns of NEW record (requires `hstore` extension)
DECLARE
r record;
BEGIN
FOR r IN SELECT (each(hstore(NEW))).*
LOOP
RAISE NOTICE '% value is %', r.key, quote_nullable(r.value);
END LOOP;
RETURN NEW;
END