Skip to content

Instantly share code, notes, and snippets.

View cedricvidal's full-sized avatar

Cedric Vidal cedricvidal

View GitHub Profile
@cedricvidal
cedricvidal / open_llm_openai.py
Last active March 7, 2024 21:56
Consume Azure AI Pay As You Go (PAYG) Open Model endpoint (Llama 2, ...)
# Those endpoints don't use the usual Azure OpenAI scheme, they use the OpenAI scheme.
# They also take the model field to route to the proper deployment, but I haven't verified this works
# Tested with openai 1.13.3
from openai import OpenAI
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s:%(lineno)d - %(message)s',
@cedricvidal
cedricvidal / uuid5_sha256.py
Created February 11, 2024 18:38
Python UUID5 using SHA-256
# Generate a UUID5 from a name using SHA-256
def uuid5_sha256(namespace, name):
"""Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
if isinstance(name, str):
name = bytes(name, "utf-8")
from uuid import UUID
import hashlib
hash = hashlib.sha256(namespace.bytes + name).digest()
return UUID(bytes=hash[:16], version=5)
@cedricvidal
cedricvidal / logging.py
Created March 28, 2023 19:55 — forked from kingspp/logging.py
Python Comprehensive Logging using YAML Configuration
import os
import yaml
import logging.config
import logging
import coloredlogs
def setup_logging(default_path='logging.yaml', default_level=logging.INFO, env_key='LOG_CFG'):
"""
| **@author:** Prathyush SP
| Logging Setup
@cedricvidal
cedricvidal / Fix Apple Photos timestamps.scpt
Last active February 13, 2023 17:28
Fix Apple Photos timestamps Applescript script
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
# This script fixes timestamps of photos currently selected in OSX Photos application.
# It does so by reading a CSV file containing mappings from file names to timestamps.
# The user is requested to select the CSV file when running this script.
# Author: Cedric Vidal (https://vidal.biz)
@cedricvidal
cedricvidal / git-move-subdir-cross-repo.sh
Last active October 4, 2019 05:13 — forked from trongthanh/gist:2779392
How to move a folder from one repo to another and keep its commit history
# source: http://st-on-it.blogspot.com/2010/01/how-to-move-folders-between-git.html
# First of all you need to have a clean clone of the source repository so we didn't screw the things up.
git clone git://server.com/my-repo1.git
# After that you need to do some preparations on the source repository, nuking all the entries except the folder you need to move. Use the following command
git filter-branch --subdirectory-filter your_dir -- -- all
# This will nuke all the other entries and their history, creating a clean git repository that contains only data and history from the directory you need. If you need to move several folders, you have to collect them in a single directory using the git mv command.
@cedricvidal
cedricvidal / gist:8e1dce995d99ddd6812df7827dfc710d
Created March 11, 2019 15:29
Extract JIRA Ticker from GIT branch name regexp
^(?'remote'[a-zA-Z]+)\/(?'sub'[a-zA-Z]+\/)?(?'jira_project'[A-Z]+)-(?'jira_ticket'[0-9]+).*$
@cedricvidal
cedricvidal / .envrc
Created February 23, 2019 10:53
Node sample direnv
# Add node_modules/.bin to PATH
layout node
set -e
# Use specific node version using nvm
NODE_VERSION_PREFIX=v
NODE_VERSIONS=~/.nvm/versions/node
use node
@cedricvidal
cedricvidal / java-collections-complexity.md
Last active July 30, 2022 15:43 — forked from psayre23/gist:c30a821239f4818b0709
Runtime Complexity of Java Collections

Below are the Big O performance of common functions of different Java Collections.

List Add Remove Get Contains Next Data Structure
ArrayList O(1) O(n) O(1) O(n) O(1) Array
LinkedList O(1) O(1) O(n) O(n) O(1) Linked List
CopyOnWriteArrayList O(n) O(n) O(1) O(n) O(1) Array
@cedricvidal
cedricvidal / git_log_csv.sh
Created January 11, 2019 17:05
Git log CSV
(SEP=",";\
echo "Hash${SEP}AuthorName${SEP}AuthorEmail${SEP}CommiterName${SEP}CommiterEmail${SEP}AuthorDate${SEP}Subject"; \
git log --pretty=format:"%h${SEP}%an${SEP}%ae${SEP}%cn${SEP}%ce${SEP}%ad${SEP}%s" --all --date=short\
)
@cedricvidal
cedricvidal / example.sql
Last active November 15, 2018 09:59
Oracle SQL Developer - Export query to CSV
SPOOL "/tmp/export.csv"
select /*csv*/ *
from ( select /*+ FIRST_ROWS(n) */
a.*, ROWNUM rnum
from ( SELECT c1, TIMESTAMP FROM mytable ORDER BY timestamp ) a
where ROWNUM <=
110 )
where rnum >= 100;
/* Source https://stackoverflow.com/questions/4168398/how-to-export-query-result-to-csv-in-oracle-sql-developer */