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 / 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 / backup.sh
Last active January 17, 2022 16:26 — forked from nherment/backup.sh
ElasticSearch log index backup & restore scripts
#!/bin/bash
# herein we backup our indexes! this script should run at like 3 AM every first day of the month, after logstash
# rotates to a new ES index and theres no new data coming in to the old one. we grab metadatas,
# compress the data files and backs up to whatever long term storage.
. ./config.sh
echo "Checking that index exist in ES"
if [ `curl -sI $ESURL/$INDEXNAME | grep OK | wc -l` -eq 0 ]
then
@cedricvidal
cedricvidal / README.md
Created November 15, 2018 09:57
Optimized Oracle pagination

Where :

  • FIRST_ROWS(N) tells the optimizer, "Hey, I'm interested in getting the first rows, and I'll get N of them as fast as possible."
  • :MAX_ROW_TO_FETCH is set to the last row of the result set to fetch—if you wanted rows 50 to 60 of the result set, you would set this to 60.
  • :MIN_ROW_TO_FETCH is set to the first row of the result set to fetch, so to get rows 50 to 60, you would set this to 50.

Source https://blogs.oracle.com/oraclemagazine/on-rownum-and-limiting-results

cat image.jpg | base64 | vault write /secret/image.jpg value=-
vault read -format=raw -field=value /secret/image.jpg | base64 --decode > image.out.jpg
@cedricvidal
cedricvidal / README.md
Created October 29, 2016 14:03
Netflix Eureka curl registration

Registration

curl -v -X POST -H "Accept: application/xml" -H "Content-type: application/xml" --data @reg.xml http://localhost:8761/eureka/apps/test

Listing

curl -X GET -H "Accept: application/json" http://localhost:8761/eureka/apps
@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.