Skip to content

Instantly share code, notes, and snippets.

View bigmasonwang's full-sized avatar

mason wang bigmasonwang

  • Adelaide
  • 06:27 (UTC -12:00)
View GitHub Profile
@zealot128
zealot128 / rails-models-to-typescript-schema.rb
Last active July 1, 2024 16:05
Simple ruby script to generate Active Record Typescript information with enums + associations
# USAGE:
# rails runner rails-models-to-typescript-schema.rb > app/javascript/types/schema.d.ts
Rails.application.eager_load!
models = ActiveRecord::Base.descendants.reject { |i| i.abstract_class? }
belongs_to = true
has_many = true
@fgilio
fgilio / axios-catch-error.js
Last active August 15, 2024 01:45
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨