Skip to content

Instantly share code, notes, and snippets.

@rphlmr
rphlmr / clear-db.ts
Last active May 13, 2024 18:51
Drizzle snippets
// Credits to Louistiti from Drizzle Discord: https://discord.com/channels/1043890932593987624/1130802621750448160/1143083373535973406
import { sql } from "drizzle-orm";
const clearDb = async (): Promise<void> => {
const query = sql<string>`SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_type = 'BASE TABLE';
`;
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active May 13, 2024 18:51
set -e, -u, -o, -x pipefail explanation
@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@niespodd
niespodd / limit_chromium_fps.patch
Last active May 13, 2024 18:48
Chromium patch to reduce CPU load on Swiftshader no-headless
/**
ref: https://cs.chromium.org/chromium/src/components/viz/common/frame_sinks/begin_frame_args.h?q=60hz&dr=C&l=11
The original 16666 corresponds to 60 Hz/FPS: (1 / 60) * 10^6 = 16666μs
**/
diff --git a/components/viz/common/frame_sinks/begin_frame_args.h b/components/viz/common/frame_sinks/begin_frame_args.h
index c4d0e29c7d65..a39ede9849c6 100644
--- a/components/viz/common/frame_sinks/begin_frame_args.h
+++ b/components/viz/common/frame_sinks/begin_frame_args.h
@@ -91,7 +91,8 @@ struct VIZ_COMMON_EXPORT BeginFrameArgs {
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.AI;
@rsms
rsms / macos-distribution.md
Created May 13, 2024 18:27
macOS distribution — code signing, notarization, quarantine, distribution vehicles
@odats
odats / merging_line_segments.py
Created August 10, 2017 12:41
Implementation of merging line segments by TAVARES and PADILHA
# TAVARES and PADILHA approach
def merge_line_segments(line_i, line_j, use_log=False):
# line distance
line_i_length = math.hypot(line_i[1][0] - line_i[0][0], line_i[1][1] - line_i[0][1])
line_j_length = math.hypot(line_j[1][0] - line_j[0][0], line_j[1][1] - line_j[0][1])
# centroids
Xg = line_i_length*(line_i[0][0]+line_i[1][0]) + line_j_length*(line_j[0][0]+line_j[1][0])
Xg /= 2 * (line_i_length + line_j_length)
@KarlRamstedt
KarlRamstedt / FirstPersonCameraRotation.cs
Created January 8, 2020 10:17
A simple First Person Camera rotation script for Unity.
using UnityEngine;
/// <summary>
/// A simple FPP (First Person Perspective) camera rotation script.
/// Like those found in most FPS (First Person Shooter) games.
/// </summary>
public class FirstPersonCameraRotation : MonoBehaviour {
public float Sensitivity {
get { return sensitivity; }