Skip to content

Instantly share code, notes, and snippets.

View itskingori's full-sized avatar
🚢
Shipping

King'ori Maina itskingori

🚢
Shipping
View GitHub Profile
@itskingori
itskingori / application_controller.rb
Last active March 4, 2024 09:07 — forked from speed-of-light/application_controller.rb
How to handle exceptions like 401, 501, 404 in Rails
# As used with CanCan and Devise
class ApplicationController < ActionController::Base
protect_from_forgery
include ErrorResponseActions
rescue_from CanCan::AccessDenied, :with => :authorization_error
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
before_filter :authenticate!
@itskingori
itskingori / README.md
Last active May 17, 2023 14:42
Handy MySQL Tips & Tricks

MySQL Notes

Scripts

  1. database-sizes.sql - To determine the sizes of all of your databases.
  2. table-sizes.sql - To determine the sizes of all of the tables in a specific database. Replace database_name with the name of the database that you want to check.
  3. new-database-with-user.sql - To create a new database and a user that has access to that database.
@itskingori
itskingori / iframe-loader.md
Last active April 11, 2023 06:37
How to add an iframe loader without JavaScript stuffs!
@itskingori
itskingori / annotator-example-plugin.js
Last active December 18, 2020 17:21
Example AnnotatorJS Plugin showing events
Annotator.Plugin.Example = function (element, options) {
var myPlugin = {};
myPlugin.pluginInit = function () {
// This annotator instance
this.annotator
// LOADING
.subscribe("annotationsLoaded", function (annotations) {
console.log("annotationsLoaded called when the annotations have been loaded.");
console.log(annotations);
@itskingori
itskingori / README.md
Last active July 26, 2019 15:37
Scripts to debug and fix weave CNI issues

Scripts

verify-weave.sh - Goes through all weave pods in the cluster, computes a checksum on the 'status ipam' list and tells you if there are any weave pods that disagree on their peer list. It was used this to identify the different groups of pods in the cluster and decide which we wanted to preserve and which ones we wanted to reset/restart. Another quick script bump-weave.sh - Used to remove the db file and restart for those weave pods we wished to reset.

Source

@itskingori
itskingori / Makefile
Created August 20, 2018 21:42
Makefile for generating TLS certs for the Prometheus custom metrics API adapter
# modified from https://github.com/stefanprodan/k8s-prom-hpa/blob/617a98c5d921c3413599bbbb1438dfb125e3bd21/Makefile
SHELL=bash
UNAME := $(shell uname)
PURPOSE:=custom-metrics-adapter
SERVICE_NAME:=custom-metrics-apiserver
ALT_NAMES:="custom-metrics-apiserver.kube-system","custom-metrics-apiserver.kube-system.svc"
SECRET_FILE:=custom-metrics-adapter-serving-certs.yml
certs: gensecret rmcerts
@itskingori
itskingori / contact_us_email.html.erb
Last active January 19, 2019 01:48
Getting started quickly with Amazon Email Sending Service (SES) and Ruby on Rails. Test in Rails 4
<p>Hello!</p>
<div>
<%= @message %>
</div>
<p>-- <%= @fullname %> (<%= @email %>)</p>
@itskingori
itskingori / annotateit-ruby-jwt.md
Last active December 24, 2017 08:01
Example to show how to integrate a site with AnnotatorJS with AnnotateIt.org Store. Includes the Javascript part as well as some server side token generators : one in Ruby and the other in Python.

Replace the Auth options hash value having token: <TOKEN_FOR_TESTING_THAT_LASTS_FOR_A_DAY> with an actual token. This token can be generated by the server side scripts and copied in. It supercedes the tokenUrl: if set.

Just to be 100% sure, feel free to verify the validity of the JSON Web Token generated using jwt.io, JWT debugger. Oh, and the TTL is set to 86400 which is a day. Enough time to generate a token and play around with it.

Ps: If there are any amendments that I can make to improve clarity or fix issues, feel free to leave a comment below. I'll get a notification and act on it as soon as I can.

Ps 2: I was experiencing an issue with CORS and so I submitted the issue (and this code) to the annotator-dev mailing list. Check the July 2014 archives for an email with the subject ... '[annotator-dev] Integrating Site With AnnotateIt Store'.

@itskingori
itskingori / README.md
Last active August 21, 2017 22:01
Testing setting environment variables in bash

Running ./test.sh gives the below output:

test1 is empty
test2 is set (empty string)
test3 is set (has string though)
test4 is not set (does not exist at all)