Skip to content

Instantly share code, notes, and snippets.

View leobessa's full-sized avatar

Leonardo Bessa leobessa

View GitHub Profile
@danielberkompas
danielberkompas / scheduler.ex
Created October 26, 2016 17:59
A simple mix task scheduler for Elixir apps
defmodule MyApp.Scheduler do
@moduledoc """
Schedules a Mix task to be run at a given interval in milliseconds.
## Options
- `:task`: The name of the Mix task to run.
- `:args`: A list of arguments to pass to the Mix task's `run/1` function.
- `:interval`: The time interval in millisconds to rerun the task.
@renatomefi
renatomefi / gen-jwt-rsa-keys.sh
Last active May 28, 2019 08:29
Generate RS256 JWT keys to use at jwt.io
#!/bin/bash
# This will write private.pem and public.pem in the current directory
# The default key strenght is 2048 bits
# usage:
# # ./gen-jwt-rsa-keys.sh mykey
# # ls
# gen-jwt-rsa-keys.sh mykey-private.key mykey-public.pem
# first time you have to give execution permission or use bash and the filename
# # chmod +x gen-jwt-rsa-keys.sh
KEYNAME=${1:-jwtrsa}
@jorgedavila25
jorgedavila25 / elastic_search_connection.rb
Last active March 11, 2020 14:03
Using Ruby's ElasticSearch gem that uses Kaminari for pagination and the Ruby GraphQL gem, this is a custom connection to bypass additional pagination. This assumes that you've already queried the correct paginated records from ElasticSearch and you're returning an `Elasticsearch::Model::Response` object.
class ElasticSearchConnection < GraphQL::Relay::BaseConnection
def has_next_page
!nodes.last_page?
end
def has_previous_page
!nodes.first_page?
end
def cursor_from_node(node)
@indiesquidge
indiesquidge / subdomain-localhost-rails-5.md
Created January 19, 2016 07:42
how to access subdomains locally with Rails 5

Subdomaining Localhost with Rails 5

I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api

Rails.application.routes.draw do
  constraints subdomain: "api" do
    scope module: "api" do
@parmentf
parmentf / GitCommitEmoji.md
Last active June 2, 2024 01:20
Git Commit message Emoji
@TomK32
TomK32 / ledger-envelope-generator.rb
Last active December 27, 2022 19:51
create ledger entries for repeating transactions
#!/bin/env ruby
# (C) 2015 Thomas R. Koll, <info@ananasblau.com>
# licensed under WTFPL
#
# This script generates entries for the ledger format.
# Think of it as an envelope generator
require 'highline'
require 'date'
require 'active_support/core_ext/date/calculations'
@OlegIlyenko
OlegIlyenko / Event-stream based GraphQL subscriptions.md
Last active May 28, 2024 17:41
Event-stream based GraphQL subscriptions for real-time updates

In this gist I would like to describe an idea for GraphQL subscriptions. It was inspired by conversations about subscriptions in the GraphQL slack channel and different GH issues, like #89 and #411.

Conceptual Model

At the moment GraphQL allows 2 types of queries:

  • query
  • mutation

Reference implementation also adds the third type: subscription. It does not have any semantics yet, so here I would like to propose one possible semantics interpretation and the reasoning behind it.

@IronSavior
IronSavior / composable_enums_demo.rb
Last active January 20, 2021 01:39
Composable Enumerators in Ruby
# @author Erik Elmore <erik@erikelmore.com>
# This is getting a little out of hand... :dizzy_face:
# For printing trace output for demonstration
module Status
def status( method_name, args = [], extra = nil )
extra = ' => %s' % extra if extra
puts '%s#%s(%s)%s' % [self.class, method_name, args.join(', '), extra]
end
end
@fxg42
fxg42 / optional.ex
Last active January 21, 2022 12:48
Maybe monad with an Elixir macro dsl
defmodule Optional do
defmacro __using__(_opts) do
quote do
require unquote(__MODULE__)
import unquote(__MODULE__)
end
end
def unit(nil), do: {:err, nil}
def unit(value), do: {:ok, value}