Skip to content

Instantly share code, notes, and snippets.

View ospaarmann's full-sized avatar
🚀
We offer software development with Elixir, React, Ruby on Rails, NodeJS, Python.

Ole Spaarmann ospaarmann

🚀
We offer software development with Elixir, React, Ruby on Rails, NodeJS, Python.
View GitHub Profile
@ospaarmann
ospaarmann / 1-form_abandonment_tracker.js
Last active March 15, 2020 22:35
Tracking form abandonment with Google Analytics and the beforeunload event
var FormAbandonmentTracker = {
init: function(gtag, form_id, event_category, event_action = 'FormAbandonment') {
this.$gtag = gtag;
this.$eventCategory = event_category ? event_category : form_id;
this.$eventAction = event_action;
this.$formHistory = [];
this.$formIsSubmitted = false;
this.$formId = form_id;
this.$form = document.getElementById(form_id);
@ospaarmann
ospaarmann / raw_gun_trace.ex
Last active December 16, 2018 17:53
Raw gun trace for gun_down issue
iex(12)> :dbg.tracer()
{:error, :already_started}
iex(13)> :dbg.tpl(:gun, [])
{:ok, [{:matched, :nonode@nohost, 73}]}
iex(14)> :dbg.tpl(:gun_http2, [])
{:ok, [{:matched, :nonode@nohost, 40}]}
iex(15)> :dbg.p(:all ,:c)
{:ok, [{:matched, :nonode@nohost, 265}]}
iex(16)> (<0.366.0>) call gun_http2:keepalive({http2_state,<0.359.0>,#Port<0.15835>,gun_tcp,#{},
[gun_data_h],
@ospaarmann
ospaarmann / tweet_consumer.ex
Created January 10, 2018 14:27
EmojiMap.TweetConsumer
defmodule EmojiMap.TweetConsumer do
@moduledoc """
The consumer side. Subscribes to the producer once it is started so when
it crashes and the supervisor restarts it, it automatically re-subscribes
"""
use GenStage
@doc """
Starts the consumer.
@ospaarmann
ospaarmann / tweet_broadcaster.ex
Created January 10, 2018 14:25
EmojiMap.TweetBroadcaster
defmodule EmojiMap.TweetBroadcaster do
@moduledoc """
When events arrive and there are no consumers, we store the event in
the queue alongside the process information that broadcasted the event. When
consumers send demand and there are not enough events, we increase the pending
demand. Once we have both the data and the demand, we acknowledge the process
that has sent the event to the broadcaster and finally broadcast the event
downstream.
This follows very closely the example in the Docs on Bufferin Demand:
https://hexdocs.pm/gen_stage/GenStage.html
@ospaarmann
ospaarmann / twitter_stream.ex
Created January 10, 2018 14:22
EmojiMap.TwitterStream
defmodule EmojiMap.TwitterStream do
@moduledoc """
We get a Twitter Stream from locations within a bounding box. The
bounding box is so large that the tweets can come from all over the world.
This way we make sure that we only receive geo-tagged tweets. The reason for
this is: It isn't possible to search for hundreds of different keywords at
once. Plus location isn't a filter. So we find tweets from either the location
OR matching the keyword. We have to filter ourself.
"""
@ospaarmann
ospaarmann / tweet_buffer_filler.ex
Last active January 10, 2018 14:21
TweetBufferFiller
defmodule EmojiMap.TweetBufferFiller do
use GenServer
alias EmojiMap.TweetBroadcaster
alias EmojiMap.TweetConsumer
alias EmojiMap.TwitterStream
def start_link(opts \\ []) do
{:ok, pid} = GenServer.start_link(__MODULE__, [], opts)
@ospaarmann
ospaarmann / my.component.ts
Created August 23, 2016 10:56
Angular 2 nl2br pipe
import { Component} from '@angular/core';
import { Nl2BrPipe } from './nl2br.pipe';
@Component({
moduleId: module.id,
selector: 'my-component',
template: `
<div [innerHtml]="content | nl2br"></div>
`