Skip to content

Instantly share code, notes, and snippets.

@grncdr
grncdr / data.csv
Created June 17, 2015 22:29
Demo of importing a CSV file into a Contentful space
first name last name age
Stephen Sugden 31
Tom Reznik 29
Justin Thomas 30
@grncdr
grncdr / 00-Readme.md
Last active March 3, 2023 05:57
Delete unused assets

Delete unused assets

This is an example script for deleting assets that aren't linked in your content model. It does this by walking through all assets and checking for any links back to them.

WARNING: This script does not take into account assets that are only linked inside of Text fields. If you primarily embed images directly using the markdown editor, this will very likely delete assets you depend on.

You must fill in your own CMA access token & space ID at the top before running

Usage

DROP DATABASE IF EXISTS stupid_simple_test;
CREATE DATABASE stupid_simple_test;
USE stupid_simple_test;
CREATE TABLE users (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) -- Should be properly encrypted in a real application!
@grncdr
grncdr / index.js
Created September 23, 2012 21:36 — forked from anonymous/index.js
Observable object properties in javascript
/**
* A quick proof-of-concept of observable objects using JS accessors
*
* Base observable objects are created with * `new Observable(names)`, where
* `names` is an array of property names that should be observable.
*
* Instances are created by calling .create(initial_data) on the resulting
* base object, and observed with their .observe(handler) method. See the bottom
* of this file for an example.
*/
@grncdr
grncdr / minimal-schema-loader.rb
Created November 5, 2021 20:41
The lowest-overhead way to get all tables & columns out of an ActiveRecord db/schema.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
module Nop
def nop(*methods)
methods.each do |method|
define_method(method) { |*_args| nil }
end
end
end
@grncdr
grncdr / machine.js
Last active May 5, 2020 15:44
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'Order',
type: 'parallel',
context: {
has_bank_info: false
},
states: {
payment: {
initial: 'estimated',
states: {
@grncdr
grncdr / machine.js
Last active August 6, 2019 15:46
Generated by XState Viz: https://xstate.js.org/viz
const invoiceMachine = Machine({
id: 'invoice',
initial: 'open',
states: {
open: {
on: {
CLOSE: {
target: 'closed',
actions: [
'open_next_invoice',
@grncdr
grncdr / set-retention-policies.sh
Created January 29, 2019 10:04
One liner for setting retention policy on a set of cloudwatch log groups
#!/bin/sh
PATTERN="my-app-production"
RETENTION_IN_DAYS="30"
for group_name in $(aws logs describe-log-groups | jq -r '.logGroups[]|.logGroupName' | grep $PATTERN); do
aws logs put-retention-policy --log-group-name $group_name --retention-in-days $RETENTION_IN_DAYS;
done
@grncdr
grncdr / git-stash-review
Created June 5, 2018 09:56
shell script for reviewing your git stashes
#!/bin/bash
RETAINED_STASHES="0"
REMAINING_STASHES=$(git stash list | wc -l)
while true; do
if [ "$REMAINING_STASHES" == "0" ]; then
echo "All done"
break
fi

Keybase proof

I hereby claim:

  • I am grncdr on github.
  • I am grncdr (https://keybase.io/grncdr) on keybase.
  • I have a public key ASDwB6kzUc-wV7jvW5RtkoQvY9KyPtA5q-7TqkxwERwkEAo

To claim this, I am signing this object: