Skip to content

Instantly share code, notes, and snippets.

View skunkworker's full-sized avatar

John Bolliger skunkworker

View GitHub Profile
@skunkworker
skunkworker / append_json_column_rails_5.rb
Last active October 11, 2022 16:13
How to append to a json column array in Rails 5.
# assuming Model is your model and options is a json/jsonb column.
# This uses the Postgres json append || operator.
# And wraps the option inside an array.
# producing [{},{}] multiple hashes inside a top level json array.
# It is very important that the hash is [{}] NOT {} as not having the array on the
# outside will cause the hash to replace the contents instead of appending to them.
new_option = [{
name: option_name,
@skunkworker
skunkworker / ActionViewController.swift
Created October 10, 2020 05:34
Use SwiftUI in Action Extension
import UIKit
import MobileCoreServices
import SwiftUI
class ActionViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Get the item[s] we're handling from the extension context.
@skunkworker
skunkworker / bump_rails_migration_timestamp.zsh
Last active April 30, 2020 18:33
Bump rails migration timestamp
alias bump_migration='rename -i -v "s/(\d{14})/$(date +'%Y%m%d%H%M%S')/" $1'
@skunkworker
skunkworker / signup.html
Created January 28, 2020 06:35
How to override sign in with google button using css selectors and psuedo elements.
<div class="g-signin2 signup-button" data-onsuccess="onSignIn" data-theme="dark" data-longtitle="true" data-width="250" data-height="50">
</div>
@skunkworker
skunkworker / component.js
Created January 1, 2020 09:46
How to use hypernova-vue with rails
console.log("hello vue")
const Vue = require("vue")
// const renderVue = require("hypernova-vue").renderVue // this throws an error.
const renderVue = require("hypernova-vue/server").renderVue
const MyComponentX = Vue.extend({
template: '<h1>hello world</h1>'
})
@skunkworker
skunkworker / route_matcher.ts
Created August 10, 2019 03:56
basic typescript route matcher
export interface StringTMap<T> { [key: string]: T; };
export interface NumberTMap<T> { [key: number]: T; };
export interface StringAnyMap extends StringTMap<any> {};
export interface NumberAnyMap extends NumberTMap<any> {};
export interface StringStringMap extends StringTMap<string> {};
export interface NumberStringMap extends NumberTMap<string> {};
export interface StringNumberMap extends StringTMap<number> {};
@skunkworker
skunkworker / directives.ts
Last active June 22, 2019 05:46
Vuejs directive, have floating window (eg custom dropdown) always be visible on the page.
import Vue from 'vue'
let handleWindowResize
export function moveFromWindowLeft(el, binding) {
const showElement = binding.value
if (!showElement) {
@skunkworker
skunkworker / vue-closable-directives.ts
Created June 19, 2019 23:15
Vue-closable directive (with fixes)
// imported from
// https://medium.com/@Taha_Shashtari/an-easy-way-to-detect-clicks-outside-an-element-in-vue-1b51d43ff634
import Vue from 'vue'
// This variable will hold the reference to
// document's click handler
let handleOutsideClick
Vue.directive('closable', {
bind (el, binding, vnode) {
@skunkworker
skunkworker / ChaffinMethod.go
Last active March 29, 2019 06:20
Transpiled ChaffinMethod to Go
/*
Package main - transpiled by c2go version: v0.25.9 Dubnium 2018-12-30
If you have found any issues, please raise an issue at:
https://github.com/elliotchance/c2go/
*/
// Warning (FieldDecl): /usr/include/_stdio.h:137 : Cannot resolve type 'int ( * _Nullable)(void *)' : Cannot separate function 'int ( * _Nullable)(void *)' : Cannot resolve type 'int ( * _Nullable)' : Cannot separate function 'int ( * _Nullable)' : Cannot resolve type '* _Nullable' : I couldn't find an appropriate Go type for the C type '* _Nullable'.
// Warning (FieldDecl): /usr/include/_stdio.h:138 : Cannot resolve type 'int ( * _Nullable)(void *, char *, int)' : Cannot separate function 'int ( * _Nullable)(void *, char *, int)' : Cannot resolve type 'int ( * _Nullable)' : Cannot separate function 'int ( * _Nullable)' : Cannot resolve type '* _Nullable' : I couldn't find an appropriate Go type for the C type '* _Nullable'.
// Warning (FieldDecl): /usr/include/_stdio.h:139 : Cannot resolve type 'fpos_t ( * _Nullable)(void *, fpos_t,
@skunkworker
skunkworker / test_job_helper.rb
Created December 30, 2017 03:02
ActiveJob run enqueued jobs without block for testing.
# this pulls out each job and runs it, then clears the job queue.
# helpful when you don't want to run inside a block.
def perform_enqueued_jobs_now
enqueued_jobs = ActiveJob::Base.queue_adapter.enqueued_jobs
enqueued_jobs.each do |item|
item[:job].perform_now(*item[:args])
ActiveJob::Base.queue_adapter.performed_jobs << item
end