Skip to content

Instantly share code, notes, and snippets.

View SetiZ's full-sized avatar

Mehdi SetiZ

View GitHub Profile
@jolbol1
jolbol1 / middleware.ts
Created May 11, 2025 22:20
Next.js Authenticated and Validated Server Action Middleware
/* eslint-disable @typescript-eslint/no-explicit-any */
import { User } from "better-auth";
import { z } from "zod";
import { auth } from "./auth";
import { headers } from "next/headers";
/**
* Represents the state of an action, including optional error and success messages.
*/
export type ActionState = {
@broofa
broofa / checkForUndefinedCSSClasses.js
Last active June 22, 2025 08:19
ES module for detecting undefined CSS classes (uses mutation observer to monitor DOM changes). `console.warn()`s undefined classes.
/**
* Sets up a DOM MutationObserver that watches for elements using undefined CSS
* class names. Performance should be pretty good, but it's probably best to
* avoid using this in production.
*
* Usage:
*
* import cssCheck from './checkForUndefinedCSSClasses.js'
*
* // Call before DOM renders (e.g. in <HEAD> or prior to React.render())
@jefBinomed
jefBinomed / PWA-console-snippets.js
Last active January 25, 2023 12:53
PWA Console Helpers
// Copy and paste the one you need
// Check current registration
navigator.serviceWorker.getRegistration()
.then(registration => console.log('Registration : ', registration));
// Cancel current registation
navigator.serviceWorker.getRegistration()
.then(async (registration)=>{
if (!registration){
@victorbruce
victorbruce / Firebase.md
Last active October 1, 2025 18:15
My journey with Firebase so far. Cheatsheet to serve as a quick reference when developing firebase applications

Firebase

Set up firebase and Deploy

  • Head over to firebase. Sign in and create a project.

  • Copy your project settings under Firebase SDK snippet into your local project (ie your project's api key, auth domain, databaseURL, etc)

  • Create a file (firebase.js or config.js Any name that suits you is fine)

@dmurawsky
dmurawsky / index.js
Last active April 22, 2025 13:06
How to make a page full height in Next.js
const FullHeightPage = () => (
<div>
Hello World!
<style global jsx>{`
html,
body,
body > div:first-child,
div#__next,
div#__next > div {
height: 100%;
@mahemoff
mahemoff / ask-wikipedia.rb
Last active August 29, 2015 13:56 — forked from emad-elsaid/ask-wikipedia.rb
Refactor processing, make script standalone with initial env, add command-line argument
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
language = 'en'
article = ARGV[0] ||
begin
print 'What do you need to know? : '
URI::encode gets.chomp
@TooTallNate
TooTallNate / mp3player.js
Created October 24, 2012 17:42
node.js command line MP3 player in 9 lines of code!
var fs = require('fs');
var lame = require('lame');
var Speaker = require('speaker');
fs.createReadStream(process.argv[2])
.pipe(new lame.Decoder())
.on('format', function (format) {
this.pipe(new Speaker(format));
});
@robflaherty
robflaherty / svg-path-to-json.py
Created January 15, 2012 16:39
Extract SVG paths and convert to JSON for use with Raphael.js
from xml.dom import minidom
import json
config = {
'svg_file' : 'map.svg',
'js_file' : 'map.js',
'js_var' : 'svgMap'
}
svg = minidom.parse(config['svg_file'])