Skip to content

Instantly share code, notes, and snippets.

View pjambet's full-sized avatar

Pierre Jambet pjambet

View GitHub Profile
@pjambet
pjambet / exception_handling.scala
Last active January 5, 2020 00:44
Exeception handling in the controller
case Failure(exception) =>
exception match {
case e: CardException =>
complete(
StatusCodes.PaymentRequired,
HttpEntity(
ContentTypes.`application/json`,
"{\"message\": \"Invalid card\", \"code\": \"" + e.declineCode + "\"}"))
case _ =>
@pjambet
pjambet / FakeService.java
Last active January 4, 2020 23:02
Checked and Unchecked exceptions in Scala
public class FakeService {
public class CustomCheckedException extends Throwable {}
public class CustomUncheckedException extends RuntimeException {}
public void doSomethingWithCheckedExceptions() throws CustomCheckedException {
throw new CustomCheckedException();
}
public void doSomethingWithUncheckedExceptions() {
try {
// Use Stripe's library to make requests...
} catch (CardException e) {
// Since it's a decline, CardException will be caught
System.out.println("Status is: " + e.getCode());
System.out.println("Message is: " + e.getMessage());
} catch (RateLimitException e) {
// Too many requests made to the API too quickly
} catch (InvalidRequestException e) {
// Invalid parameters were supplied to Stripe's API
@pjambet
pjambet / stripe_errors.md
Last active July 28, 2019 16:25
Stripe Errors
  • api_connection_error: Failure to connect to Stripe's API.
  • api_error: API errors cover any other type of problem (e.g., a temporary problem with Stripe's servers), and are extremely uncommon.
  • authentication_error: Failure to properly authenticate yourself in the request.
  • card_error: Card errors are the most common type of error you should expect to handle. They result when the user enters a card that can't be charged for some reason.
  • idempotency_error: Idempotency errors occur when an Idempotency-Key is re-used on a request that does not match the first request's API endpoint and parameters.
  • invalid_request_error: Invalid request errors arise when your request has invalid parameters.
  • rate_limit_error: Too many requests hit the API too quickly.
  • validation_error: Errors triggered by our client-side libraries when failing to validate fields (e.g., when a card number or expiration date is invalid or incomplete).
@pjambet
pjambet / 0_Routes.scala
Last active January 6, 2020 21:42
Scala Error Handling
val route =
path("order") {
post {
entity(as[OrderRequest]) { orderRequest =>
onComplete(PurchaseService.createPurchase(orderRequest)) {
case Success(result) =>
complete(StatusCodes.Created, result)
case Failure(exception) =>
system.log.error(exception, "Unexpected error")
complete(StatusCodes.InternalServerError,
<p class="subtitle">Learn how one of the web&#8217;s biggest accidental success stories evolved.</p></header></div></div><div class="site-inner"><div class="content-sidebar-wrap"><main class="content"><article class="post-9674 page type-page status-publish entry"><div class="saboxplugin-wrap"><div class="saboxplugin-gravatar"><picture width="100" height="100" alt="Claire Broadley" class="avatar avatar-100 wp-user-avatar wp-user-avatar-100 alignnone photo sp-no-webp"><source srcset="https://digital.com/wp-content/uploads/AAEAAQAAAAAAAAkMAAAAJDIwMTM5ZDdiLTQwNTMtNDMxZS1iOGJlLWZlOGI1NzlhYzFlNg-150x150.webp" type="image/webp"><source srcset="https://digital.com/wp-content/uploads/AAEAAQAAAAAAAAkMAAAAJDIwMTM5ZDdiLTQwNTMtNDMxZS1iOGJlLWZlOGI1NzlhYzFlNg-150x150.jpg"><img src="https://digital.com/wp-content/uploads/AAEAAQAAAAAAAAkMAAAAJDIwMTM5ZDdiLTQwNTMtNDMxZS1iOGJlLWZlOGI1NzlhYzFlNg-150x150.jpg" width="100" height="100" alt="Claire Broadley" class="avatar avatar-100 wp-user-avatar wp-user-avatar-100 alignnone photo s
export CPPFLAGS="-I/usr/local/opt/openssl/include -I/usr/local/opt/readline/include"
export LDFLAGS="-L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -Wl,-dead_strip_dylibs"
POSTGRES_EXTRA_CONFIGURE_OPTIONS="--with-uuid=e2fs --with-bonjour --with-openssl -v" asdf install postgres 9.6.10
@pjambet
pjambet / atomic.rb
Last active July 19, 2023 21:38
Companion code for atomic operations in sql
require 'minitest/autorun'
require 'pg'
require 'mysql2'
require 'sequel'
def get_db(database_name)
case database_name
when :pg
Sequel.connect('postgres://pierre:@localhost:5432/pierre')
when :mysql
@pjambet
pjambet / .vimrc
Last active December 13, 2015 22:25
let g:gist_post_private = 1

Keybase proof

I hereby claim:

  • I am pjambet on github.
  • I am pierrej (https://keybase.io/pierrej) on keybase.
  • I have a public key whose fingerprint is A7A2 1A00 1B8E BF41 1E54 7574 8DEF 6131 386B D257

To claim this, I am signing this object: