Skip to content

Instantly share code, notes, and snippets.

View hooopo's full-sized avatar
🍏
I may be slow to respond.

Hooopo hooopo

🍏
I may be slow to respond.
View GitHub Profile
@peterc
peterc / pg_available_extensions.txt
Created February 14, 2019 18:40
Which Postgres extensions are available on DigitalOcean's new managed PostgreSQL service?
defaultdb=> SELECT * FROM pg_available_extensions;
name | default_version | installed_version | comment
------------------------------+-----------------+-------------------+---------------------------------------------------------------------------------------------------------------------
aiven_extras | 1.0.2 | | aiven_extras
plpgsql | 1.0 | 1.0 | PL/pgSQL procedural language
btree_gist | 1.5 | | support for indexing common datatypes in GiST
tcn | 1.0 | | Triggered change notifications
seg | 1.3 | | data type for representing line segments or floating-point intervals
pgrowlocks | 1.2 |
@malakai97
malakai97 / DependencyInjectionInRuby.md
Created February 7, 2018 00:34 — forked from blairanderson/DependencyInjectionInRuby.md
Dependency Injection in Ruby. Originally from Jim Weirich’s blog which does not exist except for googles cache.

Dependency Injection in Ruby 07 Oct 04

Introduction

At the 2004 Ruby Conference, Jamis Buck had the unenviable task to explain Dependency Injection to a bunch of Ruby developers. First of all, Dependency Injection (DI) and Inversion of Control (IoC) is hard to explain, the benefits are subtle and the dynamic nature of Ruby make those benefits even more marginal. Furthermore examples using DI/IoC are either too simple (and don’t convey the usefulness) or too complex (and difficult to explain in the space of an article or presentation). I once attempted to explain DI/IoC to a room of Java programmers (see onestepback.org/articles/dependencyinjection/), so I can’t pass up trying to explain it to Ruby developers.

Thanks goes to Jamis Buck (the author of the Copland DI/IoC framework) who took the time to review this article and provide feedback.

What is Dependency Injection?

@marcocitus
marcocitus / load_github_data.sql
Last active March 12, 2019 04:02
Load data from GitHub in postgres
CREATE OR REPLACE FUNCTION public.load_github_data(events_date date, hour integer)
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
AS $function$
BEGIN
CREATE TEMPORARY TABLE input (data jsonb) ON COMMIT DROP;
EXECUTE format($$COPY input FROM PROGRAM 'curl -s http://data.githubarchive.org/%s-%s.json.gz | zcat | grep -v \\u0000' CSV QUOTE e'\x01' DELIMITER e'\x02'$$, events_date, hour);
INSERT INTO github.events SELECT
(data->>'id')::bigint AS event_id,
@theorygeek
theorygeek / association_loader.rb
Last active October 31, 2023 07:15
Preloading Associations with graphql-batch
# frozen_string_literal: true
class AssociationLoader < GraphQL::Batch::Loader
attr_reader :klass, :association
def initialize(klass, association)
raise ArgumentError, "association to load must be a symbol (got #{association.inspect})" unless association.is_a?(Symbol)
raise ArgumentError, "cannot load associations for class #{klass.name}" unless klass < ActiveRecord::Base
raise TypeError, "association #{association} does not exist on #{klass.name}" unless klass.reflect_on_association(association)
@klass = klass
@coorasse
coorasse / raven_initializer.rb
Last active June 8, 2018 07:46
Sending Sentry Raven events asynchronously with ActiveJob
Raven.configure(true) do |config|
config.async = ->(event) { SentryJob.perform_later(event) }
end
@nepsilon
nepsilon / fuzzy-search-postgres.md
Last active December 13, 2023 14:16
PostgreSQL: Native fuzzy search with levenshtein() — First published in fullweb.io issue #41

PostgreSQL: Fuzzy search with levenshtein()

Ever wanted to implement a “Did you mean?” feature in your search results? Google is said to have greatly increased its user engagement with it. Here is how to implement it simply in Postgres (v9.1+):

Install the extension:

CREATE EXTENSION fuzzystrmatch;
@xaviershay
xaviershay / standalone_rom_sql.rb
Created July 20, 2015 02:00
Standalone script to play around with ROM. http://rom-rb.org/
# Standalone script to try http://rom-rb.org/ with a database
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'rom'
gem 'rom-sql'
gem 'rom-rails'
gem 'activemodel'
@JeffBelback
JeffBelback / docker-destroy-all.sh
Last active May 25, 2024 20:19
Destroy all Docker Containers and Images
#!/bin/bash
# Stop all containers
containers=`docker ps -a -q`
if [ -n "$containers" ] ; then
docker stop $containers
fi
# Delete all containers
containers=`docker ps -a -q`
if [ -n "$containers" ]; then
docker rm -f -v $containers
@fran0x
fran0x / Dockerfile
Last active February 15, 2016 17:33
Dockerfile for Greenplum SNE 4.2.6.1
FROM centos:6.6
MAINTAINER "Francisco Lopez" [email protected]
# update & upgrade packages
RUN yum update -y & yum upgrade -y
# install extra packages and basic tools (included some required for Greenplum installer)
RUN yum install -y epel-release git unzip which tar sed wget curl nano expect
# cleanup packages
@rastermanden
rastermanden / psql2markdown
Created March 11, 2015 20:26
termial alias to convert psql output to markdown tables
alias psql2markdown=" sed 's/+/|/g' | sed 's/^/|/' | sed 's/$/|/' | grep -v rows | grep -v '||'"