Skip to content

Instantly share code, notes, and snippets.

Avatar

John Bolliger skunkworker

View GitHub Profile
@skunkworker
skunkworker / ActionViewController.swift
Created Oct 10, 2020
Use SwiftUI in Action Extension
View ActionViewController.swift
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 / example.rb
Last active Jun 13, 2020
How to append to a json column array in Rails 5.
View example.rb
# 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 / bump_rails_migration_timestamp.zsh
Last active Apr 30, 2020
Bump rails migration timestamp
View bump_rails_migration_timestamp.zsh
alias bump_migration='rename -i -v "s/(\d{14})/$(date +'%Y%m%d%H%M%S')/" $1'
@skunkworker
skunkworker / signup.html
Created Jan 28, 2020
How to override sign in with google button using css selectors and psuedo elements.
View signup.html
<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 Jan 1, 2020
How to use hypernova-vue with rails
View component.js
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 Aug 10, 2019
basic typescript route matcher
View route_matcher.ts
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 Jun 22, 2019
Vuejs directive, have floating window (eg custom dropdown) always be visible on the page.
View directives.ts
import Vue from 'vue'
let handleWindowResize
export function moveFromWindowLeft(el, binding) {
const showElement = binding.value
if (!showElement) {
@skunkworker
skunkworker / vue-closable-directives.ts
Created Jun 19, 2019
Vue-closable directive (with fixes)
View vue-closable-directives.ts
// 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 Mar 29, 2019
Transpiled ChaffinMethod to Go
View ChaffinMethod.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 Dec 30, 2017
ActiveJob run enqueued jobs without block for testing.
View test_job_helper.rb
# 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