Skip to content

Instantly share code, notes, and snippets.

@benweint
benweint / as-note-thread-safety-demo.rb
Last active April 22, 2017 15:28
This is a demo of a thread-safety issue with ActiveSupport::Notifications for Rails issue https://github.com/rails/rails/issues/12069
#!/usr/bin/env ruby
#
# When run against rails/rails commit 91684fb193a91671d682701cc1357e7b4b3fbe2b,
# this code produces the following output on my machine:
#
# long start @ 0.000
# short start @ 0.510
# short finish @ 1.511
# short reported 1.511186 s
@litera
litera / Angular.Filter.Format.js
Created March 19, 2014 03:25
string.Format for AngularJS
/* AngularJS string.Format filter
*
* This filter provides string variable replacement similar to C# string.Format("{0}", "something");
*
* Usage: {{ "From model: {0}; and a constant: {1};" | format:model.property:"constant":...:... }}
*/
(function (angular) {
angular
@murbanski
murbanski / api_clients_controller_spec.rb
Last active February 27, 2024 19:53
RSpec 3.1 and Rails 4 HTTP Digest Auth testing
# spec/controllers/api_clients_controller_spec.rb
RSpec.describe APIClientsController, type: :controller do
let(:api_client) { mock_model(APIClient) }
context "when HTTP Digest auth credentials are invalid" do
before do
authenticate_with_http_digest("invalid_login", "invalid_password") do
get :index
end
end
@adeekshith
adeekshith / .git-commit-template.txt
Last active February 21, 2024 12:06 — forked from Linell/.git-commit-template.txt
This commit message template helps you write great commit messages and enforce it across teams.
# <type>: (If applied, this commit will...) <subject> (Max 50 char)
# |<---- Using a Maximum Of 50 Characters ---->|
# Explain why this change is being made
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
# Provide links or keys to any relevant tickets, articles or other resources
# Example: Github issue #23
@dreikanter
dreikanter / encrypt_openssl.md
Last active May 2, 2024 12:55 — forked from crazybyte/encrypt_openssl.txt
File encryption using OpenSSL

Symmetic encryption

For symmetic encryption, you can use the following:

To encrypt:

openssl aes-256-cbc -salt -a -e -in plaintext.txt -out encrypted.txt

To decrypt:

Validate JSON schema in Rails

Topics

  1. What/Why JSON schema
  2. Apply to rails model validation
  3. Test your API endpoint with schema matcher
  4. Homework for a curious reader
  5. References
@lambertbrady
lambertbrady / pyodide-provider.js
Created July 13, 2021 23:35
Pyodide React Component
import { createContext, useRef, useState } from 'react'
export const PyodideContext = createContext()
export default function PyodideProvider({ children }) {
const pyodide = useRef(null)
const hasLoadPyodideBeenCalled = useRef(false)
const [isPyodideLoading, setIsPyodideLoading] = useState(true)
return (