Cinder Snippet Board

Git Rebase Interactive

git rebase -i HEAD~3
# In the editor change 'pick' to 'squash' for commits you want to combine
3
about 2 hours ago

FastAPI Hello

from fastapi import FastAPI
app = FastAPI()

@app.get('/')
def read_root():
    return {"msg": "Hello World"}
2
about 2 hours ago

Array Shuffle (JS)

function shuffle(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
}

const nums = [1,2,3,4,5];
shuffle(nums);
console.log(nums);
1
about 2 hours ago

CSS Center Flex

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.box {
  width: 200px;
  height: 200px;
  background: #4f46e5;
}
2
about 2 hours ago

Bash Loop Files

#!/usr/bin/env bash

for file in *.txt; do
  echo "Processing $file"
  wc -l "$file"
 done
3
about 2 hours ago

SQL Count Users

SELECT COUNT(*) AS user_count
FROM users
WHERE created_at > now() - interval '7 days';
2
about 2 hours ago

Git Rebase Interactive

git rebase -i HEAD~3
# In the editor change 'pick' to 'squash' for commits you want to combine
2
about 2 hours ago

FastAPI Hello

from fastapi import FastAPI
app = FastAPI()

@app.get('/')
def read_root():
    return {"msg": "Hello World"}
2
about 2 hours ago

Array Shuffle (JS)

function shuffle(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    [array[i], array[j]] = [array[j], array[i]];
  }
}

const nums = [1,2,3,4,5];
shuffle(nums);
console.log(nums);
2
about 2 hours ago

CSS Center Flex

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.box {
  width: 200px;
  height: 200px;
  background: #4f46e5;
}
2
about 2 hours ago

Bash Loop Files

#!/usr/bin/env bash

for file in *.txt; do
  echo "Processing $file"
  wc -l "$file"
 done
4
about 2 hours ago

SQL Count Users

SELECT COUNT(*) AS user_count
FROM users
WHERE created_at > now() - interval '7 days';
2
about 2 hours ago

Python Context Manager

from contextlib import contextmanager

@contextmanager
def open_file(path, mode):
    f = open(path, mode)
    try:
        yield f
    finally:
        f.close()

with open_file('example.txt', 'r') as f:
    data = f.read()
2
about 2 hours ago

Python Context Manager

from contextlib import contextmanager

@contextmanager
def open_file(path, mode):
    f = open(path, mode)
    try:
        yield f
    finally:
        f.close()

with open_file('example.txt', 'r') as f:
    data = f.read()
4
about 3 hours ago

Debounce Function (JS)

function debounce(fn, delay) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn.apply(this, args), delay);
  };
}

const log = debounce(console.log, 300);
log('Hello');
log('World');
5
about 4 hours ago

Debounce Function (JS)

function debounce(fn, delay) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn.apply(this, args), delay);
  };
}

const log = debounce(console.log, 300);
log('Hello');
log('World');
2
about 4 hours ago