Skip to content

Instantly share code, notes, and snippets.

View fduan's full-sized avatar

Qingfeng Frank Duan fduan

  • Research Triangle Park, NC
View GitHub Profile
@ArturT
ArturT / api_controller.rb
Last active July 20, 2023 06:44
How to rescue ActionDispatch::Http::MimeNegotiation::InvalidType in API controller for Rails 6.1+ and render nice JSON error. Learn more how you could run RSpec/Minitest tests faster in Rails app https://docs.knapsackpro.com/2020/how-to-speed-up-ruby-and-javascript-tests-with-ci-parallelisation
# This is example how to rescue from exception ActionDispatch::Http::MimeNegotiation::InvalidType
# and show nice JSON error in your API
module API
class BaseController < ActionController::API
def process_action(*args)
super
rescue ActionDispatch::Http::MimeNegotiation::InvalidType => exception
# set valid Content-Type to be able to call render method below
request.headers['Content-Type'] = 'application/json'
render status: 400, json: { errors: [exception.message] }
@tinkerrc
tinkerrc / ftc_cv_tutorial.org
Last active November 15, 2023 02:21
An introduction to EasyOpenCV for FTC. Example OpMode for FTC SkyStone (2019-2020)

FTC CV Tutorial

Introduction

Hello, I am Zhenkai from Team Wolf Corp (#12525). In FTC autonomous period, computer vision allows your robot to identify and distinguish scoring elements and make the optimal move. In this tutorial, I will cover the basics of EasyOpenCV and how to identify SkyStones from the 2019-2020 season. This tutorial assumes basic knowledge of FTC programming using Java.

Set up the Environment

@barbolo
barbolo / benchmark_xml_render.rb
Created July 18, 2018 16:52
This is a comprehensive XML generation benchmark with some of the most popular Ruby gems
# gem install benchmark-memory activesupport builder nokogiri rabl ox libxml-ruby
require 'benchmark'
require 'benchmark-memory'
require 'builder'
require 'active_support/core_ext/hash/conversions'
require 'rabl'
require 'nokogiri'
require 'libxml'
require 'ox'
@jjb
jjb / file.md
Created February 4, 2018 16:27
Active Record Connection Management in Rails 5.1 or lower
@ryanermita
ryanermita / rails_locking.md
Last active December 12, 2024 07:03
Optimistic and Pessimistic Locking in Rails

Optimistic Locking assumes that a database transaction conflict is very rare to happen. It uses a version number of the record to track the changes. It raise an error when other user tries to update the record while it is lock.

usage

Just add a lock_version column to the table you want to place the lock and Rails will automatically check this column before updating the record.

Pessimistic locking assumes that database transaction conflict is very likely to happen. It locks the record until the transaction is done. If the record is currently lock and the other user make a transaction, that second transaction will wait until the lock in first transaction is release.

usage

@andreicristianpetcu
andreicristianpetcu / ansible-summary.md
Created May 30, 2016 19:25
This is an ANSIBLE Cheat Sheet from Jon Warbrick

An Ansible summary

Jon Warbrick, July 2014, V3.2 (for Ansible 1.7)

Configuration file

intro_configuration.html

First one found from of

@maxivak
maxivak / readme.md
Last active October 18, 2025 00:23
Integrating Gem/Engine and Main Rails App
@jamesyang124
jamesyang124 / ruby_meta.md
Last active December 15, 2025 13:08
Ruby meta programming

Ruby Metaprogramming Guide

Note: This guide works with Ruby 2.6+ through Ruby 3.x, with modern Ruby 3.x features highlighted where applicable. Core metaprogramming concepts remain consistent across Ruby versions.

This document has been collaboratively updated and modernized through an interactive process with Claude Code, revised with examples, visual diagrams, and Ruby 3.x compatibility.

Table of Contents

  1. Key Concepts
  2. Self
@grenade
grenade / 01-generate-ed25519-ssh-key.sh
Last active February 13, 2026 03:03
generate ed25519 ssh and gpg/pgp keys and set file permissions for ssh keys and config
#!/bin/bash
mkdir -p ~/.ssh
# generate new personal ed25519 ssh keys
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "rob thijssen <rthijssen@gmail.com>"
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_robtn -C "rob thijssen <rob@rob.tn>"
# generate new host cert authority (host_ca) ed25519 ssh key
# used for signing host keys and creating host certs