Skip to content

Instantly share code, notes, and snippets.

Daniel Hanke thedanielhanke

Block or report user

Report or block thedanielhanke

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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
View rspec_delegate_matcher.rb
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it 'delegates name to Author' do
# expect subject.to delegate(:name).to(:author).with_prefix # post.author_name
# end
# it 'delegates month to creation date' do
# expect subject.to delegate(:month).to :created_at
@thedanielhanke
thedanielhanke / gist:6e0a067e1c2dc1e6cb23
Created Feb 23, 2016 — forked from jeffsheets/gist:5292986
Hibernate DetachedCriteria using subqueries exists clause, while eager fetching the lazy collection that is in the exists clause, and running via Spring HibernateTemplate findByCriteria, and limit results to max of 2000.
View gist:6e0a067e1c2dc1e6cb23
/*
* HQL would look something like this:
*
* from Person p join fetch p.addresses address
* where exists (
* from Address addr left join addr.state st
* where addr.personId = p.id
* and st.abbreviation = :abbreviation
* )
*/
You can’t perform that action at this time.