Skip to content

Instantly share code, notes, and snippets.

View andrewmcnamara's full-sized avatar

Andrew McNamara andrewmcnamara

  • Sydney, Australia
View GitHub Profile
@gaearon
gaearon / 00-README-NEXT-SPA.md
Last active July 19, 2024 06:35
Next.js SPA example with dynamic client-only routing and static hosting

Next.js client-only SPA example

Made this example to show how to use Next.js router for a 100% SPA (no JS server) app.

You use Next.js router like normally, but don't define getStaticProps and such. Instead you do client-only fetching with swr, react-query, or similar methods.

You can generate HTML fallback for the page if there's something meaningful to show before you "know" the params. (Remember, HTML is static, so it can't respond to dynamic query. But it can be different per route.)

Don't like Next? Here's how to do the same in Gatsby.

@cj
cj / [trpc].ts
Created August 23, 2022 03:05
Astro trpc client handler
import { appRouter } from 'server'
import type { APIContext } from 'astro'
import { resolveHTTPResponse } from '@trpc/server'
import type { HTTPHeaders } from '@trpc/client'
/**
* Handles trpc query client requests.
*
* @param {APIContext} - Astro API Context
* @returns {Promise<Response>} - trpc response
@na2hiro
na2hiro / Remix-request-cheatsheet.md
Last active July 4, 2024 04:16
Remix request cheatsheet
@yahonda
yahonda / ruby31onrails.md
Last active June 25, 2024 20:26
Ruby 3.1 on Rails

Ruby 3.1 on Rails

Actions required to use Ruby 3.1.0 with Rails

Rails 7.0.Z

  • Rails 7.0.1 is compatible with Ruby 3.1.0.
  • Rails 7.0.1 addes net-smtp, net-imap and net-pop gems as Action Mailbox and Action Mailer dependency, you do not need to add them explicitly in your application Gemfile anymore.
  • thor 1.2.1 has been released. You will not see DidYouMean::SPELL_CHECKERS.merge deprecate warnings anymore.

Rails 6.1.Z

  • Use Rails 6.1.5 to support database.yml with aliases and secrets.yml with aliases.
@NikolaDespotoski
NikolaDespotoski / KSPExtensions.kt
Last active February 19, 2023 05:56
KSP extensions
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}"
@swinton
swinton / README.md
Last active May 14, 2024 10:06
Automatically sign your commits from GitHub Actions, using the REST API

Verified commits made easy with GitHub Actions

image

So you want to commit changes generated by a GitHub Actions workflow back to your repo, and have that commit signed automatically?

Here's one way this is possible, using the REST API, the auto-generated GITHUB_TOKEN, and the GitHub CLI, gh, which is pre-installed on GitHub's hosted Actions runners.

You don't have to configure the git client, just add a step like the one below... Be sure to edit FILE_TO_COMMIT and DESTINATION_BRANCH to suit your needs.

{"contents":{"css":{"validate":false},"editor":{"formatOnSave":true},"eslint":{"enable":true},"files":{"exclude":{"build/**":false,"dist/**":false,"out/**":false,"test/coverage/**":false}},"less":{"validate":false},"prettier":{"eslintIntegration":false,"stylelintIntegration":false},"search":{"exclude":{"**/build":true,"**/coverage":true,"**/deps":true,"**/node_modules":true,"**/out":true,"**/test":false}},"scss":{"validate":true},"tasks":{"version":"2.0.0","type":"shell","tasks":[{"label":"Jest","command":"${workspaceFolder}/node_modules/.bin/jest","args":["--no-cache"],"options":{"env":{"NODE_ENV":"test","SAVI_ENV":"test"}},"group":"test","presentation":{"clear":true,"panel":"shared","reveal":"always"}},{"label":"Jest - Run Test","command":"${workspaceFolder}/node_modules/.bin/jest","args":["${file}","--detectOpenHandles","--no-cache"],"options":{"env":{"BABEL_ENV":"test","NODE_ENV":"test","SAVI_ENV":"test"}},"group":"test","presentation":{"clear":true,"panel":"shared","reveal":"always"}},{"label":"Jest - Up
@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active July 18, 2024 16:00
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Font
:set guifont=Source\ Code\ Pro:h14
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Hide pointless junk at the bottom, doesn't work in .vimrc for some reason?
:set laststatus=0
:set noshowmode "don't show --INSERT--
:set noruler "don't show line numbers/column/% junk
@fnky
fnky / ANSI.md
Last active July 22, 2024 12:03
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27