Skip to content

Instantly share code, notes, and snippets.

@charlieanstey
charlieanstey / index.js
Last active October 16, 2022 22:23
URL-safe encoding/decoding of JSON data like Pendo does it
// Given large data payload with UTF-6 encoding, emojis etc.
const data = [{...}]
const string = JSON.stringify(data); // JSON to string
const byteArray = new TextEncoder().encode(string) // Convert to bytes
const deflatedByteArrayBuffer = zlib.deflateSync(byteArray); // Compress
const encoded = deflatedByteArrayBuffer.toString("base64url"); // Encode for safe transfer e.g. via URL
// URL-safe output
console.log(encoded)
#!/usr/bin/env bash
#Fix starting screen setup issue https://github.com/getsentry/sentry/issues/12722
echo "Set config.yml"
cat <<EOT > config.yml
auth.allow-registration: false
beacon.anonymous: true
mail.backend: 'smtp'
mail.from: "foo@example.com"
@charlieanstey
charlieanstey / phpmyadmin_docker.sh
Created May 1, 2018 12:05
#PHPMyAdmin on #Docker
docker run \
--name myadmin \
--detach \
--restart always \
--link mysql:db \
--publish 8080:80 \
phpmyadmin/phpmyadmin:4.8.0.1
@charlieanstey
charlieanstey / redis_docker.sh
Created May 1, 2018 11:47
#Redis on #Docker
docker run \
--detach \
--restart always \
--name redis \
--publish 6379:6379 \
redis:alpine
@charlieanstey
charlieanstey / ReactComponentHydrator.cs
Last active May 1, 2018 11:23
React component hydrator #C# #React
using Newtonsoft.Json;
using React;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Umbraco.CMS.Helpers
{
/// <summary>
/// Service helper to provide React Component config(s) required to hydrate on client-side
@charlieanstey
charlieanstey / colorpicker.html
Last active April 1, 2019 13:37 — forked from pbres/colorpicker.html
ColorPicker for Umbraco Grid DataType Settings/Style sections
<div ng-controller="Umbraco.PropertyEditors.ColorPickerController">
<ul class="thumbnails color-picker">
<li ng-repeat="preval in model.prevalues" ng-class="{active: model.value === preval.value}">
<a ng-click="toggleItem(preval)" class="thumbnail" hex-bg-color="{{preval.color}}">
</a>
<span class="color-label" ng-bind="preval.key"></span>
</li>
</ul>
<input type="hidden" name="modelValue" ng-model="model.value" val-property-validator="validateMandatory"/>
@charlieanstey
charlieanstey / the-bind-problem.jsx
Created November 14, 2017 09:28 — forked from Restuta/the-bind-problem.jsx
React, removeEventListener and bind(this) gotcha
/* Sometimes it's pretty easy to run ito troubles with React ES6 components.
Consider the following code: */
class EventStub extends Component {
componentDidMount() {
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResize.bind(this));
@charlieanstey
charlieanstey / symm_diff.js
Created July 2, 2017 22:07
Symmetric diff of 2 JavaScript object arrays. Written in ES6 and checks against a numeric 'id' property in each object. Returns an object of added and removed arrays
_diffById(newArr, oldArr) {
function notContainedIn(arr) {
return function arrNotContains(element) {
return arr.map(el => { return el.id }).indexOf(element.id) === -1
}
}
return {
added: newArr.filter(notContainedIn(oldArr)),
removed: oldArr.filter(notContainedIn(newArr))
}
@charlieanstey
charlieanstey / mongodb_learninglocker_docker.sh
Last active May 1, 2018 11:30
#MongoDB for LearningLocker on #Docker #Shell
docker run \
--detach \
--restart always \
--name mongo \
--publish 27017:27017 \
--volume /Users/Charlie/Docker/Volumes/mongo-data:/data/db \
--volume /Users/Charlie/Docker/Volumes/mongo-config:/data/configdb \
mongo:3.4.14-jessie --auth
docker exec -it mongo mongo admin
@charlieanstey
charlieanstey / address.json
Last active August 29, 2015 14:23
Parse address object
{
"line1": "Cotton Court",
"line2": "Church Street",
"city": "Preston",
"region": "Lancashire",
"country": "United Kingdom",
"postcode": "PR1 3BY",
"timezone": "Europe/London",
"geopoint": {
"__type": "GeoPoint",