Skip to content

Instantly share code, notes, and snippets.

View stevenroh's full-sized avatar
🇨🇭

Steven Roh stevenroh

🇨🇭
View GitHub Profile
@chadmuro
chadmuro / Auth.js
Last active August 31, 2023 23:03
Supabase Auth Context
import React, { useContext, useState, useEffect, createContext } from 'react';
import { supabase } from '../supabase';
// create a context for authentication
const AuthContext = createContext();
export const AuthProvider = ({ children }) => {
// create state values for user data and loading
const [user, setUser] = useState();
const [loading, setLoading] = useState(true);
@timgaunt
timgaunt / List Product Data.sql
Created February 20, 2017 18:17
List uCommerce product data in an importable format
USE MarkerTechV2CMS
GO
WITH Fields
AS
(
SELECT
pd.ProductDefinitionId [ChildDefinitionID]
, pd.ProductDefinitionId
, pd.Name AS [ProductDefinitionName]
@joepie91
joepie91 / random.md
Last active April 11, 2025 09:42
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@qstudio
qstudio / pll_copy_post_metas.php
Last active September 15, 2021 16:36
WP / PolyLang / Un-Sync Specified Custom Fields
<?php
// filter to exclude specified post_meta from Polylang Sync ##
add_filter( 'pll_copy_post_metas', 'q_pll_copy_post_metas' );
/**
* Remove defined custom fields from Polylang Sync
*
* @since 0.1
* @param Array $metas
@bradenbest
bradenbest / convert
Last active December 11, 2016 04:27
Easy batch-converter for audio formats
#!/bin/bash
# Converts audio formats in bulk
# requires avconv
fformat=m4a
tformat=mp3
c=0
t=0
files=*.$fformat
@dideler
dideler / example.md
Last active November 14, 2024 03:33
A python script for extracting email addresses from text files.You can pass it multiple files. It prints the email addresses to stdout, one address per line.For ease of use, remove the .py extension and place it in your $PATH (e.g. /usr/local/bin/) to run it like a built-in command.
@billerickson
billerickson / genesis-custom-loop-pagination.php
Created July 31, 2012 15:59
Genesis custom loop with pagination
<?php
/* Template Name: Test */
/**
* Genesis custom loop
*/
function be_custom_loop() {
global $post;
// arguments, adjust as needed