Skip to content

Instantly share code, notes, and snippets.

Archonic archonic

Block or report user

Report or block archonic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@archonic
archonic / badge_helper.rb
Created Sep 13, 2018
Ruby font colour based on background colour. Outputs white or black based on hex luminance.
View badge_helper.rb
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 Sep 1, 2018
Google Kubernetes Engine (GKE) Rails deploy script
View gke_deploy.sh
# 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 Mar 23, 2018
Bootstrap 4 modals for Rails ujs data-confirm
View modals.coffee
# 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 Apr 25, 2016
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.
View temp_dump.py
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 Mar 4, 2016
Advanced Custom Forms input.js with Diac's fix, minified
View input.min.js
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
WordPress Geo Products. Depends on ACF for location meta. Replaces product search to include distance query.
View wp_geo_products.php
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 Aug 29, 2015
Hashbuddy Activity Slug Fix
View hashbuddy.php
<?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 Mar 24, 2015
Canvas child starting point
View style.css
/*
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
@archonic
archonic / index.html
Created Mar 13, 2015
Paper.js Fluid Simulation with particles (doesn't do a great job of it)
View index.html
<html>
<head>
<title>Fluid simulation with balls</title>
<script type="text/javascript" src="paper-full.js"></script>
<!-- Define inlined PaperScript associate it with myCanvas -->
<script type="text/paperscript" canvas="myCanvas">
// Ball variables
radius = 20;
totalBalls = 100;
You can’t perform that action at this time.