Skip to content

Instantly share code, notes, and snippets.

View c-spencer's full-sized avatar

Chris Spencer c-spencer

View GitHub Profile
pub fn access_token() -> BoxedFilter<(String,)> {
let (set_token_value, token_value) =
tokio_sync::watch::channel::<Option<gcloud::GrantedToken>>(None);
let channel_lock = tokio_sync::lock::Lock::new(set_token_value);
warp::any()
.and_then(move || {
let current_value = token_value.get_ref().clone().filter(|t| t.is_valid());
let result = match current_value {

Keybase proof

I hereby claim:

  • I am c-spencer on github.
  • I am cagspencer (https://keybase.io/cagspencer) on keybase.
  • I have a public key whose fingerprint is 6941 F445 2599 B7BC FF92 F7B1 E091 D260 3D41 E23C

To claim this, I am signing this object:

defp(do_decide(:accept_charset_exists?, var!(conn))) do
if(has_header(var!(conn), "accept-charset")) do
case(handle_decision(var!(conn), (
charset = ConNeg.find_best(:charset, var!(conn).assigns().headers()["accept-charset"], @available_charsets)
{!is_nil(charset), assign(var!(conn), :charset, charset)}
))) do
{true, var!(conn)} ->
do_decide(:if_match_exists?, var!(conn))
{false, var!(conn)} ->
do_decide(:handle_not_acceptable, var!(conn))
@c-spencer
c-spencer / a.ex
Last active August 29, 2015 14:11
defmodule WrangleTest.Disabled do
use Wrangle
plug :serve
decide :service_available?, do: false
end
# compiled decision tree
defmodule MyApp.UserResource do
use Phoenix.Resource
defp get_user(%{"id" => id}) do
Repo.get(User, id)
end
def supported_formats do
["html", "json", "xml"]
end
var functions = {
add: function (args) {
return args.reduce(function (a, b) { return a + b });
},
twoarg: function (a, b) {
return a * b;
},
async: function (a, cb) {
var state = this.state;
setTimeout(function () {
# current
("You came in " <> case(plural("en", :ordinal, args[:place])) do
"few" ->
to_string(args[:place]) <> "rd"
"one" ->
to_string(args[:place]) <> "st"
"other" ->
to_string(args[:place]) <> "th"
"two" ->
to_string(args[:place]) <> "nd"
LANG=en
This is a comment that precedes the strings.
@test message
Hello from the translator.
-- and this is a comment inbetween strings
@test message 2
@c-spencer
c-spencer / message_format.ex
Last active August 29, 2015 14:10
Simple and incomplete MessageFormat compiler for Elixir
defmodule Plural do
require Record
Record.defrecordp :xmlAttribute, Record.extract(:xmlAttribute, from_lib: "xmerl/include/xmerl.hrl")
Record.defrecordp :xmlText, Record.extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl")
defmacro __using__(_env) do
quote do
@before_compile Plural
Module.register_attribute(__MODULE__, :plurals, accumulate: true)
@c-spencer
c-spencer / sysdea.clj
Last active December 24, 2015 01:59
Simple experiment in ClojureScript approach to Sysdea documents with undo/redo
; adapted from clojure.core.incubator
(defn dissoc-in
"Dissociates a number of entries from the object at the given path,
removing empty maps on the path.
e.g. (dissoc-in {:a {:b {:e 6} :c 6}} [:a :b] [:e]) -> {:a {:c 6}}"
[m [k & ks :as keys] rems]
(if k
(if-let [nextmap (get m k)]
(let [newmap (dissoc-in nextmap ks rems)]
(if (seq newmap)