Skip to content

Instantly share code, notes, and snippets.

@archonic
archonic / _index_item.haml
Last active March 23, 2021 21:07
Rails generic edit-in-place feature using Stimulus.
.row.no-gutters.attachment_item.my-3{ class: "resource_#{resource.id}", data: { controller: "edit-in-place", "edit-in-place-update-url": resource_path(resource.id), "edit-in-place-resource": "resource" } }
.col
%input{ type: :hidden, name: "attachment_detail[attachment_id]", value: file.id }
%h6
%span{ data: { target: "edit-in-place.input", fieldtype: "text", attr: "name", value: resource.name } }
%p
%span{ data: { target: "edit-in-place.input", fieldtype: "textarea", attr: "description", value: resource.description } }
.col-auto.pull-right
.btn-group{ role: "group" }
%button.btn.btn-sm{ type: "button", data: { action: "edit-in-place#editMode", target: "edit-in-place.editBtn" } }
---
# INGRESS
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/whitelist-source-range: 0.0.0.0/0,::/0
creationTimestamp: 2019-12-30T23:04:50Z
generateName: cm-acme-http-solver-
@archonic
archonic / badge_helper.rb
Created September 13, 2018 20:26
Ruby font colour based on background colour. Outputs white or black based on hex luminance.
def text_colour(bg_colour)
rgb = [bg_colour[0..1], bg_colour[2..3], bg_colour[4..5]].map! do |c|
c = c.to_i(16).to_f / 255.0
c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055)**2.4
end
(0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]) <= 0.5 ? "fff" : "000"
end
@archonic
archonic / gke_deploy.sh
Last active April 30, 2020 07:59
Google Kubernetes Engine (GKE) Rails deploy script
# gke_deploy.sh
# Make sure we're in the right project and authenticated
gcloud config set project your-project
# Needed this on first run https://github.com/kubernetes/kubernetes/issues/30617
# gcloud config set container/use_client_certificate True
# Regional cheaper than zonal and acceptable for staging
gcloud container clusters get-credentials staging \
--zone northamerica-northeast1-a --project your-project
@archonic
archonic / modals.coffee
Last active February 12, 2021 15:08
Bootstrap 4 modals for Rails ujs data-confirm
# Modified from https://github.com/ifad/data-confirm-modal/blob/master/vendor/assets/javascripts/data-confirm-modal.js
$ ->
###*
# Builds the markup for a [Bootstrap modal](https://getbootstrap.com/docs/4.0/components/modal/)
# for the given `element`. Uses the following `data-` parameters to
# customize it:
#
# * `data-confirm`: Contains the modal body text. HTML is allowed.
# Separate multiple paragraphs using \n\n.
# * `data-commit`: The 'confirm' button text. "Confirm" by default.
@archonic
archonic / temp_dump.py
Last active April 25, 2016 20:25
Dumps temperature data to Mongo, theoretically. I'm running a weird version of Mongo (packaged with a fork of meteor) so this hasn't worked yet.
import os, glob, sched, time, sys
from w1thermsensor import W1ThermSensor
from pymongo import MongoClient
from datetime import datetime
# Run mongo if it's not already running
#mongod
# Sensor array
sensors_available = W1ThermSensor.get_available_sensors([W1ThermSensor.THERM_SENSOR_DS18B20])
@archonic
archonic / input.min.js
Created March 4, 2016 03:15
Advanced Custom Forms input.js with Diac's fix, minified
var acf={ajaxurl:"",admin_url:"",wp_version:"",post_id:0,nonce:"",l10n:null,o:null,helpers:{get_atts:null,version_compare:null,uniqid:null,sortable:null,add_message:null,is_clone_field:null,url_to_object:null},validation:null,conditional_logic:null,media:null,fields:{date_picker:null,color_picker:null,Image:null,file:null,wysiwyg:null,gallery:null,relationship:null}};!function($){acf.helpers.isset=function(){var e=arguments,t=e.length,a=null,n;if(0===t)throw new Error("Empty isset");for(a=e[0],i=1;i<t;i++){if(e[i]===n||a[e[i]]===n)return!1;a=a[e[i]]}return!0},acf.helpers.get_atts=function(e){var t={};return $.each(e[0].attributes,function(e,i){"data-"==i.name.substr(0,5)&&(t[i.name.replace("data-","")]=i.value)}),t},acf.helpers.version_compare=function(e,t){if(typeof e+typeof t!="stringstring")return!1;for(var i=e.split("."),a=t.split("."),n=0,s=Math.max(i.length,a.length);s>n;n++){if(i[n]&&!a[n]&&parseInt(i[n])>0||parseInt(i[n])>parseInt(a[n]))return 1;if(a[n]&&!i[n]&&parseInt(a[n])>0||parseInt(i[n])<parseIn
@archonic
archonic / wp_geo_products.php
Created May 22, 2015 22:16
WordPress Geo Products. Depends on ACF for location meta. Replaces product search to include distance query.
class WP_Query_Geo extends WP_Query {
private $lat = NULL;
private $lng = NULL;
private $distance = NULL;
/**
* Constructor - adds necessary filters to extend Query hooks
*/
public function __construct( $args = array() ) {
// Extract Latitude
@archonic
archonic / hashbuddy.php
Last active August 29, 2015 14:17
Hashbuddy Activity Slug Fix
<?php
if ( !defined( 'ABSPATH' ) ) exit;
function hashbuddy_activity_hashtags_filter( $content ) {
global $bp;
$pattern = '/[#]([\p{L}_0-9a-zA-Z-]+)/iu';
// Old line
@archonic
archonic / style.css
Created March 24, 2015 16:29
Canvas child starting point
/*
Theme Name: Canvas Child
Description: Canvas Child Theme Description
Author: Joshua Mark
Template: canvas
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: canvas, wddm, cats
Text Domain: canvas-child