Skip to content

Instantly share code, notes, and snippets.

View andrewmcnamara's full-sized avatar

Andrew McNamara andrewmcnamara

  • Sydney, Australia
View GitHub Profile
@andrewmcnamara
andrewmcnamara / AppContext.java
Created February 22, 2023 06:26 — forked from mdread/AppContext.java
get access to the Spring application context from a non-managed bean
import org.springframework.context.ApplicationContext;
public class AppContext {
private static ApplicationContext context;
public static void setApplicationContext(ApplicationContext applicationContext) {
context = applicationContext;
}
@andrewmcnamara
andrewmcnamara / DynamicProxies.kt
Created February 19, 2023 20:16 — forked from SupaHam/DynamicProxies.kt
Dynamic Proxies with Kotlin for accessing private classes.
/*
* Code by @vmironov on Kotlinlang slack.
*
* This code uses dynamic proxies in Java to make it easier to access inaccessible classes via an accessible representation.
*/
inline fun <reified T : Any> createMirror(value: Any) = createMirror(value, T::class.java)
fun <T> createMirror(value: Any, clazz: Class<T>): T {
val loader = clazz.classLoader
import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.symbol.*
/**
* Reified function to check if receiver [KSType] is assignable from [T] class
*/
inline fun <reified T> KSType.isAssignableFrom(resolver: Resolver): Boolean {
val classDeclaration = requireNotNull(resolver.getClassDeclarationByName<T>()) {
"Unable to resolve ${KSClassDeclaration::class.simpleName} for type ${T::class.simpleName}"
@andrewmcnamara
andrewmcnamara / CrudRepositoryProposal.kt
Created January 20, 2023 04:57 — forked from paulschuetz/CrudRepositoryProposal.kt
Exposed 0.30.2 CrudRepository Proposal
abstract class CrudRepository <ID, DOMAIN, TABLE : Table> {
abstract val table: TABLE
abstract fun toDomain(row: ResultRow): DOMAIN
abstract fun toRow(domain: DOMAIN): TABLE.(InsertStatement<Number>) -> Unit
abstract fun match(id: ID): SqlExpressionBuilder.() -> Op<Boolean>
abstract fun extractId(domain: DOMAIN): ID
abstract fun updateRow(domain: DOMAIN): TABLE.(UpdateStatement) -> Unit
/**
* Get a particular record by its ID.
@andrewmcnamara
andrewmcnamara / export-sync-bookmarks.js
Created May 30, 2022 22:24 — forked from ilokhov/export-sync-bookmarks.js
Node.js script for exporting and synchronising bookmarks from Google Chrome
const fs = require("fs");
const path = require("path");
function newItem(name, url) {
return { name, url };
}
const bookmarkPath = path.join(
process.env.HOME,
"/Library/Application Support/Google/Chrome/Default/Bookmarks"
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
@andrewmcnamara
andrewmcnamara / gist:99d63d4d62cfd0a9197be8f0159eee3a
Created July 19, 2019 04:55 — forked from ryanlecompte/gist:1283413
Providing an ActiveRecord-like before_filter capability to arbitrary Ruby classes
# First the end result of what we want:
class Foo
before_hook :whoa
before_hook :amazing
def test
puts "This is kinda cool!"
end
# Copyright (c) 2014 Lukas Fittl <lukas@pganalyze.com>
#
# Released in the public domain - fork as you wish.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'curses'
gem 'mixlib-cli'
@andrewmcnamara
andrewmcnamara / Fastfile
Created June 20, 2016 20:38 — forked from kennydee/Fastfile
Fastfile for staging environment with Appetize.io on React Native (iOs & Android), with statuses update on Github Enterprise
require 'httparty'
fastlane_version "1.95.0"
default_platform :ios
before_all do
# put here your token and iOs scheme app
ENV["GITHUB_TOKEN"] = "---"
ENV["APPETIZE_TOKEN"] = "---"
ENV["APP_IOS_SCHEME"] = "---"
@andrewmcnamara
andrewmcnamara / react-native-notes.md
Created May 31, 2016 21:48
Things I learned the hard way using React Native

Things I learned the hard way using React Native

Set up your environment carefully: It's important to have one canonical source of truth per environment, per platform. (i.e. iOS Development, iOS Testflight, iOS Production, ditto Android.) Every time you build, your config should propagate values from one input source (per platform) to either Java/JavaScript or Objective-C/JavaScript. Here's what we did for Android and here's what we did for iOS. I don't doubt that you can do better. Please do better. But you can't say that we didn't have one canonical source of truth that worked very simply and effectively throughout the development process.

Don't wait until the end to develop Android and iOS concurrently: Even if you're not actively focusing on both platforms, don't assume that "RN is cross platform… we can develop iOS and flip the Android switch when we'r