Skip to content

Instantly share code, notes, and snippets.

@citrus
citrus / pinia.ts
Created December 9, 2022 17:41
Add Pinia stores as global properties in Vue3 plugin with Typescript
import type { App } from 'vue'
import { useAppStore, useAuthStore } from '@/stores'
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$app: ReturnType<typeof useAppStore>
$auth: ReturnType<typeof useAuthStore>
}
}
@citrus
citrus / populateWithDotSyntax.js
Created November 10, 2021 15:13
Transform an object into an object with its values as deeply nested keys to themselves
const isLiteralObject = (object => !!object && object.constructor === Object)
function populateWithDotSyntax (object, parent = null) {
return Object.entries(object).reduce((obj, [ key, value ]) => {
const string = parent !== null ? `${parent}.${ key }` : key
if (isLiteralObject(value)) {
obj[key] = populateWithDotSyntax(value, string)
} else if (Array.isArray(value)) {
obj[key] = value.map((i, index) => populateWithDotSyntax(i, `${key}.${index}`))
} else {
@citrus
citrus / index.js
Created June 8, 2021 18:55
Netlify plugin to contextualize vite env vars.
module.exports = {
onPreBuild: () => {
const BRANCH = process.env.BRANCH.toUpperCase().replace(/-/g, '_')
console.log('Vite env plugin starting for branch:', BRANCH)
Object.keys(process.env).sort().forEach(key => {
if (!key.startsWith('VITE_') || key.endsWith(`_${BRANCH}`)) {
return
}
const contextualValue = process.env[`${key}_${BRANCH}`]
@citrus
citrus / run.txt
Created July 29, 2020 18:13
Transaction rollback failing
TransactionTest
test:Transaction should properly save record. PASS (0.07s)
Validation failed: Url can't be blank
test:Transaction should rollback record. FAIL (0.03s)
Expected: false
Actual: true
minitest (5.14.1) lib/minitest/assertions.rb:183:in `assert'
minitest (5.14.1) lib/minitest/assertions.rb:218:in `assert_equal'
test/test_helper.rb:129:in `assert_equal'
test/transaction_test.rb:25:in `block in <class:TransactionTest>'
@citrus
citrus / clear-sidekiq-jobs.rb
Last active February 27, 2020 00:26 — forked from wbotelhos/clear-sidekiq-jobs.sh
Clear Sidekiq Jobs
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
@citrus
citrus / modal.css
Last active December 18, 2019 23:45
Simple Modal
.modal {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
Jul 27 16:41:49 my-app app/web.1: 2018-07-27 23:41:49 +0000: Rack app error handling request { GET /assets/my-asset.gif }
Jul 27 16:41:49 my-app app/web.1: #<NotImplementedError: NotImplementedError>
Jul 27 16:41:49 my-app app/web.1: /app/vendor/bundle/ruby/2.2.0/gems/rack-cache-1.8.0/lib/rack/cache/meta_store.rb:179:in `purge'
Jul 27 16:41:49 my-app app/web.1: /app/vendor/bundle/ruby/2.2.0/gems/rack-cache-1.8.0/lib/rack/cache/meta_store.rb:46:in `lookup'
Jul 27 16:41:49 my-app app/web.1: /app/vendor/bundle/ruby/2.2.0/gems/rack-cache-1.8.0/lib/rack/cache/context.rb:173:in `lookup'
Jul 27 16:41:49 my-app app/web.1: /app/vendor/bundle/ruby/2.2.0/gems/rack-cache-1.8.0/lib/rack/cache/context.rb:66:in `call!'
Jul 27 16:41:49 my-app app/web.1: /app/vendor/bundle/ruby/2.2.0/gems/rack-cache-1.8.0/lib/rack/cache/context.rb:51:in `call'
Jul 27 16:41:49 my-app app/web.1: /app/vendor/bundle/ruby/2.2.0/gems/newrelic_rpm-4.7.1.340/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in `call'
Jul 27 16:41:4
@citrus
citrus / QuotePDFGenerator.apex
Last active June 12, 2022 06:02
Generate Quote PDF via Salesforce REST API
global class QuotePDFGenerator {
@future(callout=true)
public static void AttachPDFToQuote(String Id) {
try {
CreateQuoteDocumentFromPDF(Id);
} catch(exception ex) {
System.debug('Error: ' + ex);
}
}
@citrus
citrus / -
Created January 17, 2018 18:33
id: A unique integer identifier for the event
=> :provider_event_id
title: The title of the event
=> :title
url: URL of the event on seatgeek.com – you should direct users here to search for tickets
=> :affiliate_url
datetime_local: Date/time of the event in the local timezone of the venue – you will generally want to display this to users
#!/bin/sh
if [ -z "$1" ]
then
echo "You must specify a namespace to flatten" 1>&2
exit 1
else
namespace=$1
fi