Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Hanke thedanielhanke

  • awesome pants
  • Cologne, Germany
View GitHub Profile
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@thedanielhanke
thedanielhanke / integer.rb
Created Jan 26, 2021 — forked from pithyless/integer.rb
Ruby Integer::MAX and Integer::MIN
View integer.rb
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
View auto_treebuilder_test.py
"""
Defines a function `auto_insert` to help with
`pygit2.Repository.TreeBuilder`s.
Just create the top-level `TreeBuilder`, and it will handle all subtree
creation if you give it paths.
"""
import shutil
from tempfile import mkdtemp
View nodegit-write.js
{
//given:
const repo - bare Repository {}
const branchCommit = repo.getBranchCommit(branchName),
// actual method:
open: async (fn) => {
const tree = await branchCommit.getTree();
const treeBuilder = await nodegit.Treebuilder.create(repo, tree);
@thedanielhanke
thedanielhanke / tutorial.md
Created Aug 9, 2018 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API
View tutorial.md

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.

@thedanielhanke
thedanielhanke / evacuation.rb
Created Jan 29, 2018 — forked from tayeke/evacuation.rb
Example of how to do a live streaming Rails 4 model and controller using postgresql pubsub. + event module for formatting SSE.
View evacuation.rb
class Evacuation < ActiveRecord::Base
def self.notify_person_found
connection.execute "NOTIFY evac, #{connection.quote 'found person'}"
end
def self.on_person_found
@thedanielhanke
thedanielhanke / evacuation.rb
Created Jan 29, 2018 — forked from tayeke/evacuation.rb
Example of how to do a live streaming Rails 4 model and controller using postgresql pubsub. + event module for formatting SSE.
View evacuation.rb
class Evacuation < ActiveRecord::Base
def self.notify_person_found
connection.execute "NOTIFY evac, #{connection.quote 'found person'}"
end
def self.on_person_found
@thedanielhanke
thedanielhanke / embed.rb
Created Nov 28, 2017 — forked from iblue/embed.rb
ActiveRecord embedding
View embed.rb
module ActiveRecord
# Allows embedding of ActiveRecord models.
#
# Embedding other ActiveRecord models is a composition of the two
# and leads to the following behaviour:
#
# - Nested attributes are accepted on the parent without the _attributes suffix
# - Mass assignment security allows the embedded attributes
# - Embedded models are destroyed with the parent when not appearing in an update again
# - Embedded documents appears in the JSON output
@thedanielhanke
thedanielhanke / nginx.conf
Created Jul 24, 2016 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
View nginx.conf
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@thedanielhanke
thedanielhanke / attributes.rb
Created Mar 26, 2016
from outside immutable class attributes
View attributes.rb
module Attributes
def has_attributes(*key_names)
key_names.each do |key_name|
define_method key_name do
instance_variable_get("@attributes")[key_name]
end
define_method "#{key_name}=" do |value|
instance_variable_get("@attributes")[key_name] = value
end
end