Skip to content

Instantly share code, notes, and snippets.

@canburaks
canburaks / pydantic_model_shim.py
Last active June 8, 2025 22:36
A shim for Pydantic models. When `SkipJsonSchema` is not sufficient, use this.
import copy
import inspect
import sys
import typing
from typing import (
Any,
Dict,
FrozenSet,
List,
Set,
@canburaks
canburaks / shello.fish
Created September 19, 2023 18:01
This is the fish configuration function for the shello app.
function shello
set envFilePath $HOME/Library/Containers/app.shello/Data/envs/$argv;
# Check if the file exists
if [ -f "$envFilePath" ]
while read -la line
set --local key (echo "$line" | cut -d '=' -f1);
set --local value (echo "$line" | cut -d '=' -f2-);
# Set the environment variable
set -gx $key $value;
# 👀 uncomment the line below if you want to print each key
@canburaks
canburaks / get-google-drive-image.ts
Created August 25, 2022 19:56
Get the source url of the image which Google Drive link is known.
/**
* let the URL of the known image located in Google Drive is
* let image_url = 'https://drive.google.com/file/d/1uD5rSY3eBp4y4HldnxeeRq3_wU9ZKxog/view?usp=sharing'
* then image id would be 1uD5rSY3eBp4y4HldnxeeRq3_wU9ZKxog
*/
export function getDriveImageSourceId(source: string) {
const match = source.match(/d\/([^/]*)/);
if (match) {
return match[1];
<script type="application/ld+json">
{
"@context":"http://schema.org/",
"@type":"Article",
"name":"A Brief History of Emoji",
"headline": "A Brief History of Emoji",
"url":"https://www.collecteurs.com/article/a-brief-history-of-emoji",
"about": [
{
"@type": "Thing",
export default (str) => {
str = String(str).toString();
str = str.replace(/^\s+|\s+$/g, ""); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
const swaps = {
'0': ['°', '₀', '۰', '0'],
'1': ['¹', '₁', '۱', '1'],
'2': ['²', '₂', '۲', '2'],
@canburaks
canburaks / effect
Created May 1, 2022 13:11
A starting gist for CSS
/* Input placeholder animations */
::placeholder {
transition: all 350ms ease;
}
.your-input-class:focus::placeholder {
transform: translate(20px, 0);
opacity: 0;
}
function extract_text(txt) {
let innerText = ""
let txtType = Object.prototype.toString.call(txt)
// String header
if (txtType === '[object String]') {
innerText = txt
}
// Anchor header
else if (txtType === '[object Object]') {
innerText = txt.props.children
// Hook
function useOnClickOutside(ref, handler) {
useEffect(
() => {
const listener = (event) => {
// Do nothing if clicking ref's element or descendent elements
if (!ref.current || ref.current.contains(event.target)) {
return;
}
handler(event);
export function useDebounce(value, delay) {
// State and setters for debounced value
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(
() => {
// Update debounced value after delay
const handler = setTimeout(() => {
setDebouncedValue(value);
}, delay);
export function useWindowSize(initialWidth, initialHeight) {
const [windowSize, setWindowSize] = useState({
width: isClient ? window.innerWidth : initialWidth,
height: isClient ? window.innerHeight : initialHeight,
});
useEffect(() => {
function resizeHandler() {
if (windowSize.width !== window.innerWidth || windowSize.height !== window.innerHeight) {