Skip to content

Instantly share code, notes, and snippets.

@smoak
smoak / eventhooks
Created June 24, 2011 23:21
Event Hooks for python
class EventHook(object):
def __init__(self):
self.__handlers = []
def addHandler(self, handler):
self.__handlers.append(handler)
def removeHandler(self, handler):
self.__handlers.remove(handler)
@smoak
smoak / blog.ex
Last active March 29, 2018 21:09
defmodule Blog do
def fetch(limit, offset \\ 0) do
IO.inspect(limit: limit, offset: offset)
posts = 1..1000 |> Enum.map(fn i -> %{body: "body #{i}"} end)
%{
total_count: length(posts),
posts: posts |> Enum.slice(offset || 0, limit)
}
end
query {
user(id: "12345") {
id
}
viewer {
user {
id
}
}
}
object :user do
field :id, non_null(:id)
end
object :group do
field :id, non_null(:id)
field :members, list_of(:user)
end
query do
defmodule Schema do
use Absinthe.Schema
object :user do
field :id, non_null(:id)
end
object :viewer do
field :user, non_null(:user) do
resolve(fn _parent, _args, _ctx ->
@smoak
smoak / nhl_api.ex
Created January 26, 2018 05:03
Trying to use dataloader with absinthe
defmodule NhlGraphApi.NhlApi do
def data() do
Dataloader.KV.new(&fetch/2)
end
def fetch(_batch_key, arg_maps) do
IO.inspect(arg_maps: arg_maps)
%{%{id: "1"} => %{id: 1, name: "foo", city: "bar", abbreviation: "OMG"}}
end
end
@smoak
smoak / schema.ex
Last active November 16, 2017 03:38
defmodule ApiWeb.Schema do
use Absinthe.Schema
import Absinthe.Resolution.Helpers
import_types Absinthe.Type.Custom
@desc "A user"
object :user do
field :id, non_null(:string)
package com.reststopperpro.android.activity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
@smoak
smoak / BaseScreen.java
Created April 26, 2016 06:56
Trying to understand box2d
package com.mygdx.game.screen;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
@smoak
smoak / gist:6499344
Created September 9, 2013 18:10
My vimrc
call pathogen#infect()
set nocompatible
set autoindent
set modelines=5
syntax on
filetype plugin indent on
set background=dark
set number
set tabstop=2
set shiftwidth=2