Skip to content

Instantly share code, notes, and snippets.

@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 (

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
@dreikanter
dreikanter / encrypt_openssl.md
Last active November 6, 2024 13:46 — 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:

@adeekshith
adeekshith / .git-commit-template.txt
Last active October 20, 2024 21:10 — 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
@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
@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
@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
@bunnymatic
bunnymatic / custom_array_matchers.rb
Last active July 3, 2020 21:24
RSpec Matchers for increasing/decreasing array tests. Useful when sort may not be the easiest way to do things.
RSpec::Matchers.define :be_monotonically_increasing do
match do |actual|
derivative = actual.each_cons(2).map{|x, y| y <=> x}
derivative.all?{|v| v >= 0}
end
failure_message_for_should do |actual|
"expected array #{actual.inspect} to be monotonically increasing"
end
@johanneswuerbach
johanneswuerbach / .travis.yml
Last active May 14, 2024 03:50
Deploy an iOS app to testflight using Travis CI
---
language: objective-c
before_script:
- ./scripts/travis/add-key.sh
after_script:
- ./scripts/travis/remove-key.sh
after_success:
- ./scripts/travis/testflight.sh
env:
global:
@wrburgess
wrburgess / gist:5528649
Last active September 13, 2024 19:00
Backup Heroku Postgres database and restore to local database

Grab new backup of database

Command: heroku pgbackups:capture --remote production

Response: >>> HEROKU_POSTGRESQL_COLOR_URL (DATABASE_URL) ----backup---> a712

Get url of backup download

Command: heroku pgbackups:url [db_key] --remote production