Skip to content

Instantly share code, notes, and snippets.

View thedanielhanke's full-sized avatar

Daniel Hanke thedanielhanke

  • RE: GmbH
  • Cologne, Germany
View GitHub Profile
@thedanielhanke
thedanielhanke / docker-api-port.md
Created March 15, 2024 08:26 — forked from styblope/docker-api-port.md
Enable TCP port 2375 for external connection to Docker

Enable TCP port 2375 for external connection to Docker

See this issue.
Docker best practise to Control and configure Docker with systemd.

  1. Create daemon.json file in /etc/docker:

     {"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]}
    
@thedanielhanke
thedanielhanke / postgres_queries_and_commands.sql
Created June 23, 2021 21:11 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- 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 January 26, 2021 15:09 — forked from pithyless/integer.rb
Ruby Integer::MAX and Integer::MIN
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
@thedanielhanke
thedanielhanke / auto_treebuilder_test.py
Created November 20, 2018 22:58 — forked from uniphil/auto_treebuilder_test.py
pygit2 auto treebuilder
"""
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
{
//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 August 9, 2018 10:47 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API

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 January 29, 2018 22:10
Example of how to do a live streaming Rails 4 model and controller using postgresql pubsub. + event module for formatting SSE.
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 January 29, 2018 22:10
Example of how to do a live streaming Rails 4 model and controller using postgresql pubsub. + event module for formatting SSE.
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 November 28, 2017 19:23 — forked from iblue/embed.rb
ActiveRecord embedding
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 July 24, 2016 22:15 — 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/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048