Skip to content

Instantly share code, notes, and snippets.

# frozen_string_literal: true
class SlowCall
def self.work
@work ||= Concurrent::Promises.future(name: "load #{self.class.name}") do
sleep 2
Time.now
end
end
end
package main
import (
"fmt"
"reflect"
"net/url"
)
type ExampleType struct {
Name string `url:"name"`
@carymrobbins
carymrobbins / setup-postgresql-vagrant.md
Last active May 4, 2023 10:22
Configure PostgreSQL in a Vagrant guest to allow connections from the host.

Configure Postgres

  • Update pg_hba.conf (most likely in /etc/postgresql/9.4/main) with -
    • host all all 0.0.0.0/0 trust
  • Update postgresql.conf to use listen_addresses = '*'
  • Be sure to sudo service postgresql restart

Configure Vagrant

@larskanis
larskanis / pg_log_unable_to_send.rb
Last active June 20, 2022 13:36
Monkey patch PG::Connection to get more a descriptive error message
require 'pg'
class PG::Connection
def self.wrap_send_method(meth)
alias_method "#{meth}_wo_wrap", meth
define_method(meth) do |*args|
begin
send("#{meth}_wo_wrap", *args)
rescue PG::UnableToSend => e
@crucialfelix
crucialfelix / angular-speedball.js
Last active August 29, 2015 14:06
Angular Speedball - a jasmine testing utility to eliminate boilerplate in testing
'use strict';
/**
*
* An Angular Jasmine testing utility
*
* @copyright 2013 Chris Sattinger
* MIT License
*
* automatically injects these services:
* '$httpBackend', '$rootScope', '$controller', '$compile'
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@abyx
abyx / angular-error-handling.js
Last active February 4, 2022 19:19
AngularJS HTTP Error Handling Mechanism
var HEADER_NAME = 'MyApp-Handle-Errors-Generically';
var specificallyHandleInProgress = false;
angular.module('myApp').factory('RequestsErrorHandler', ['$q', function($q) {
return {
// --- The user's API for claiming responsiblity for requests ---
specificallyHandled: function(specificallyHandledBlock) {
specificallyHandleInProgress = true;
try {
return specificallyHandledBlock();
@kirkbushell
kirkbushell / interceptor.js
Created June 11, 2014 15:27
Angular JS HTTP response interceptor
/**
* Interceptor
* Implements functionality to catch various requests and fire events when they happen. This is generally to ensure
* that responses from the server are handled in a uniform fashion across the application. Also, by firing events
* it allows to have any number of handlers attach to the response.
*
* @author Kirk Bushell
* @date 28th March 2013
*/
var module = angular.module('core.interceptor', []);
@yitsushi
yitsushi / EventSystem.js
Created May 6, 2014 09:52
EventSystem that I use with React.js to communicate between components
var EventSystem = (function() {
var self = this;
self.queue = {};
return {
publish: function (event, data) {
var queue = self.queue[event];
if (typeof queue === 'undefined') {
@adamJLev
adamJLev / mixins.py
Last active November 14, 2022 15:54
(DEPRECATED) Atomic transactions and Django Rest Framework
# NOTE This is probably no longer needed, now DRF does this
# automatically if you have ATOMIC_REQUESTS enabled.
# https://github.com/encode/django-rest-framework/pull/2887
from django.db import transaction
class AtomicMixin(object):
"""
Ensures we rollback db transactions on exceptions.