Skip to content

Instantly share code, notes, and snippets.

View tyteen4a03's full-sized avatar

Timothy Choi tyteen4a03

View GitHub Profile
@tyteen4a03
tyteen4a03 / JobStopsListenerField.tsx
Last active December 13, 2023 10:18
PayloadCMS Listener Field Pattern
import { gql, useQuery } from "@apollo/client";
import { useForm } from "payload/components/forms";
import { useDocumentInfo } from "payload/dist/admin/components/utilities/DocumentInfo";
import { Job } from "payload/generated-types";
import { useEffect } from "react";
import React from "react";
const WarehouseIdQuery = gql(/* GraphQL */ `
query WarehouseIdQuery {
Addresses(where: { type: { equals: warehouse } }) {
@tyteen4a03
tyteen4a03 / generate-password.js
Created December 5, 2023 12:20
Generate Microsoft-friendly random passwords
const VOWELS = 'aeiou';
const CONSONANTS = 'bcdfghjklmnpqrstvwxyz';
const generateInitialPassword = () => {
const vowel = VOWELS[Math.floor(Math.random() * VOWELS.length)]
const consonant = CONSONANTS[Math.floor(Math.random() * CONSONANTS.length)]
const randomNumber = Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000;
return `${consonant.toLocaleUpperCase()}${vowel}${consonant}${vowel}${randomNumber}`;
}
@tyteen4a03
tyteen4a03 / PayloadFormExample.tsx
Created October 30, 2023 15:47
Payload Form Example
import { Gutter } from "payload/components/elements";
import { Form, FormSubmit, RenderFields, fieldTypes } from "payload/components/forms";
import { DefaultTemplate } from "payload/components/templates";
import { AdminViewComponent } from "payload/config";
import { useStepNav } from "payload/dist/admin/components/elements/StepNav";
import { Field } from "payload/types";
import React, { useEffect } from "react";
import { useTranslation } from "react-i18next";
const PayloadFormExample: AdminViewComponent = () => {
@tyteen4a03
tyteen4a03 / field-example.ts
Created October 30, 2023 12:37
PayloadCMS ColoredSelectCell
{
name: "jobStatus",
type: "select",
required: true,
defaultValue: "toBeAssigned",
options: [
{
label: "To Be Assigned",
value: "toBeAssigned",
},
job "mongodb" {
datacenters = ["prod-azure"]
type = "service"
constraint {
distinct_hosts = true
}
update {
max_parallel = 1
@tyteen4a03
tyteen4a03 / gist:195e09bc2c0e4169ff5d7a783f17ba14
Created April 4, 2020 13:04
code2pdf output HTML instead
require 'cgi'
require 'shellwords'
class ConvertToPDF
PDF_OPTIONS = {
page_size: 'A4'
}.freeze
def initialize(params = {})
if !params.key?(:from) || params[:from].nil?
@tyteen4a03
tyteen4a03 / delete_all_contact.py
Last active November 30, 2019 22:25
Freshdesk delete all contacts
import requests
api_key = ('API-KEY-HERE', 'X')
domain = 'DOMAIN-HERE'
contact_ids = []
page = 1
while True:
print("Downloading page {} of deleted contacts".format(page))
results = requests.get("https://{}.freshdesk.com/api/v2/contacts?page={}&per_page=100&state=deleted".format(domain, page), auth=api_key).json()
@tyteen4a03
tyteen4a03 / convertDates.py
Created July 21, 2017 11:33
a quick and dirty way to convert US dates to British dates generated by Facebook Page Insights
import csv
import re
with open("test.csv", "r+") as f:
with open("testoutput.csv", "w+") as g:
reader = csv.DictReader(f)
writer = csv.DictWriter(g, reader.fieldnames)
for row in reader:
date = row["Posted"]
m = re.match(r"^(\d\d)/(\d\d)(.*)$", date)
@tyteen4a03
tyteen4a03 / Gruntfile.js
Created May 13, 2015 14:42
XenForo development helper scripts
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to match all subfolders:
// 'test/spec/**/*.js'
module.exports = function (grunt) {
@tyteen4a03
tyteen4a03 / gist:3420a9e121d13b091343
Last active November 13, 2022 14:35
Shopify handleize function in JavaScript
// from https://github.com/Shopify/liquid/blob/63eb1aac69a31d97e343822b973b3a51941c8ac2/performance/shopify/shop_filter.rb#L100
Shopify.handleize = function (str) {
str = str.toLowerCase();
var toReplace = ['"', "'", "\\", "(", ")", "[", "]"];
// For the old browsers
for (var i = 0; i < toReplace.length; ++i) {
str = str.replace(toReplace[i], "");
}