Skip to content

Instantly share code, notes, and snippets.

@rphlmr
rphlmr / clear-db.ts
Last active March 24, 2024 21:45
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';
`;
@alexy4744
alexy4744 / closure-table.repository.ts
Last active February 27, 2024 08:19
MikroORM Closure Table Repository
import { Constructor } from "@mikro-orm/core";
import { EntityRepository, Knex } from "@mikro-orm/postgresql";
type Node = string;
export interface ClosureTableRepository<Entity> extends EntityRepository<Entity> {
containsDescendant(parent: Node, descendant: Node): Promise<boolean>;
findDescendants(parent: Node): Knex.QueryBuilder;
insertLeafNode(leaf: Node, parent: Node): Promise<void>;
insertRootNode(root: Node): Promise<void>;
@peterbrinck
peterbrinck / cookier_banner.html
Created April 3, 2020 06:55
Simple cookie-banner with AlpineJS - original by @lepikhinb
<div x-data="{ show: !localStorage.getItem('hide-banner')}">
<div x-show="show">
<button type="button" @click="localStorage.setItem('hide-banner', true); show = false;">
OK!
</button>
</div>
</div>
@SebastianHGonzalez
SebastianHGonzalez / useQueryState.ts
Last active January 9, 2024 10:28
useQueryState - query string synchronized use state hook for next.js
import { useState, useEffect } from "react";
import { useRouter } from "next/router";
type IParam = string;
type IValue = string | string[] | number | number[] | null | undefined;
type IState = { [k: string]: IValue };
type IQuery = IState;
type IRoute = string;
function isEmpty(value: IValue): boolean {
@syntagmatic
syntagmatic / Heatmap
Created March 21, 2012 07:16
heatmap.js
var defaults = {
dotsize: 5,
gutsize: 1,
totsize: 6
}
function heatmap(id, data, options) {
var self = {};
var options = _.extend(defaults, options);
self.data = data || [];
@pvinis
pvinis / face_detector.rb
Created December 7, 2011 12:06
run with "macruby face_detector.rb" or "macruby face_detector.rb https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc7/304055_10150415385415891_522505890_10347873_1682210515_n.jpg?dl=1" for a photo of me with woody and buzz lightyear :p
framework 'Cocoa'
class NSColor
def toCGColor
color_RGB = colorUsingColorSpaceName(NSCalibratedRGBColorSpace)
## approach #1
# components = Array.new(4){Pointer.new(:double)}
# color_RGB.getRed(components[0],
# green: components[1],
# blue: components[2],
@jasondavies
jasondavies / README.md
Created October 13, 2011 11:49
Zoom/Pan Map Example

Demonstrates using d3.behavior.zoom with a geographic projection. Based on an example by Iain Dillingham.

@benjchristensen
benjchristensen / index.html
Created August 16, 2011 03:21
Animated Line Graphs / Sparklines using SVG Path and d3.js
<html>
<head>
<title>Animated Sparkline using SVG Path and d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
/* tell the SVG path to be a thin blue line without any area fill */
path {
stroke: steelblue;
stroke-width: 1;
fill: none;
@iadvize
iadvize / strophe.xdomainrequest.js
Created January 6, 2011 11:15
A Strophe plugin by iAdvize that use the XdomainRequest if found (Internet Explorer)
Strophe.addConnectionPlugin("xdomainrequest", {
init: function () {
if (window.XDomainRequest) {
Strophe.debug("using XdomainRequest for IE");
// override thee send method to fire readystate 2
XDomainRequest.prototype.oldsend = XDomainRequest.prototype.send;
XDomainRequest.prototype.send = function() {
XDomainRequest.prototype.oldsend.apply(this, arguments);
this.readyState = 2;
@jeremi
jeremi / fabfile.py
Created November 4, 2010 21:00
A fabfile to manage git+appengine deployement
from __future__ import with_statement
import functools
import os
import sys
from fabric.api import *
from fabric.colors import green, red, green
import datetime
import re