Skip to content

Instantly share code, notes, and snippets.

Avatar

Paul Dlug pdlug

View GitHub Profile
@pdlug
pdlug / index.ts
Last active Oct 21, 2018
Example of embedding Apollo GraphQL server inside next.js
View index.ts
import * as express from 'express'
import * as next from 'next'
import { ApolloServer, gql } from 'apollo-server-express'
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev, quiet: false })
const handle = app.getRequestHandler()
@pdlug
pdlug / contribs.clj
Created Feb 4, 2015
Demo of parsing JATS XML using `clojure.data.zip.xml` to extract contributors.
View contribs.clj
(ns jats.contribs
(:require [clojure.java.io :as io]
[clojure.zip :as zip]
[clojure.data.xml :as xml]
[clojure.data.zip.xml :as zx]
[clojure.pprint :as pprint])
(:gen-class :main true))
(defn contrib-name [name]
(let [first-name (zx/xml1-> name :given-names zx/text)
View paul.zsh-theme
# Paul's ZSH Theme, based on several others
PROMPT='$(_user_host)${_current_dir}$(git_prompt_info)%{$reset_color%}${_return_status}%# '
local _current_dir="%3~ "
local _return_status="%{$fg[red]%}%(?..⍉)%{$reset_color%}"
local _hist_no="%{$fg[grey]%}%h%{$reset_color%}"
function _user_host() {
if [[ -n $SSH_CONNECTION ]]; then
View pacer_loop_test.rb
require 'bundler/setup'
require 'pacer'
require 'pacer-neo4j'
#graph = Pacer.tg
graph = Pacer.neo4j('/tmp/test-neo4j')
c1 = graph.create_vertex(name: 'Concept 1')
c2 = graph.create_vertex(name: 'Concept 2')
@pdlug
pdlug / gist:1072288
Created Jul 8, 2011
Test AMQP consumer/producer with auto recovery
View gist:1072288
# CONSUMER:
require 'amqp'
def setup_connection(connection)
puts "Setting up connection"
channel = AMQP::Channel.new(connection, :auto_recovery => true)
channel.on_error do |ch, channel_close|
raise channel_close.reply_text
end
@pdlug
pdlug / gist:962855
Created May 9, 2011
AMQP connection failure handling
View gist:962855
def setup_connection(connection)
# open channel, set up exchanges and bindings, subscribe
end
AMQP.start(
:host => '127.0.0.1',
:vhost => '/search',
:timeout => 0.3,
:on_tcp_connection_failure => Proc.new { |settings| puts "Failed to connect"; EM.stop }) do |connection, open_ok|
View gist:356879
describe "when handling results" do
before(:each) do
AMQP.stub!(:connect)
MQ.stub!(:new)
Nanite::MapperProxy.new('mapperproxy', {})
@instance = Nanite::MapperProxy.instance
@fanout = stub(:fanout, :publish => true)
@instance.amqp.stub!(:fanout).and_return(@fanout)
@payload = {:payload => ['nanite', 'eventmachine', 'rabbitmq']}
end
View gist:31202
require 'rubygems'
gem 'dm-core'
gem 'dm-types'
require 'dm-core'
require 'dm-types'
class User
include DataMapper::Resource
View gist:30901
describe DataMapper::Types::Slug do
before(:all) do
class SlugTest
include DataMapper::Resource
property :id, Serial
property :name, Slug
property :title, String
property :title_slug, Slug