Skip to content

Instantly share code, notes, and snippets.

Avatar
🏃‍♂️

Aaron Cruz mraaroncruz

🏃‍♂️
View GitHub Profile
@Manzanit0
Manzanit0 / ci-simple.yaml
Last active Jun 28, 2022
Elixir CI with Github Actions
View ci-simple.yaml
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
env:
MIX_ENV: test
jobs:
@andrebrait
andrebrait / keychron_linux.md
Last active Sep 23, 2022
Keychron keyboards on Linux + Bluetooth fixes
View keychron_linux.md

Here is the best setup (I think so :D) for K-series Keychron keyboards on Linux.

Most of these commands have been tested on Ubuntu 20.04 and should also work on most Debian-based distributions. If a command happens not to work for you, take a look in the comment section.

Make Fn + F-keys work

Keychron Keyboards on Linux use the hid_apple driver (even in Windows/Android mode), both in Bluetooth and Wired modes. By default, this driver uses the F-keys as multimedia shortcuts and you have to press Fn + the key to get the usual F1 through F12 keys.

@Sheikh2Imran
Sheikh2Imran / decorators.py
Last active Dec 21, 2021
Custom method decorator in Django
View decorators.py
def authentication_decorator(function):
def wrap(request, *args, **kwargs):
user_token = request.META.get('HTTP_AUTHORIZATION')
user_response, status_code = backend_obj.get_user(user_token)
if status_code == 200:
kwargs = user_response
return function(request, *args, **kwargs)
return wrap
@sivers
sivers / podcast.rb
Created Oct 29, 2019
Podcast RSS generator in Ruby
View podcast.rb
#!/usr/bin/env ruby
require 'date'
require 'xml'
def htmlit(infile)
lines = File.readlines(infile)
/<!--\s+(.+)\s+-->/.match lines.shift
lines.unshift('<h2>%s</h2>' % $1)
html = ''
lines.each do |line|
@alvinncx
alvinncx / config.exs
Last active Feb 4, 2021
Getting Phoenix.PubSub & Phoenix.LiveView to work together
View config.exs
# Configures the endpoint
config :example, Example.Endpoint,
...
pubsub: [name: Example.PubSub, adapter: Phoenix.PubSub.PG2],
...
@mraaroncruz
mraaroncruz / ethereum.rb
Created Nov 8, 2018
Use your key with a contract in ruby
View ethereum.rb
key = Eth::Key.new(priv: YOUR_PRIVATE_KEY)
client = Ethereum::HttpClient.new(...)
client.default_account = key.address
contract = Ethereum::Contract.create(...)
contract.key = key
View iam_admin_policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Resource": "arn:aws:s3:::*"
@vdbelt
vdbelt / cloudflare-purge-cache-service-worker.js
Created Aug 21, 2018
A CloudFlare service worker that proxies purge cache requests. Example: https://example.com/__purge_cache?zone=XX
View cloudflare-purge-cache-service-worker.js
addEventListener('fetch', event => {
event.respondWith(purgeCache(event.request))
})
async function purgeCache(request) {
const url = new URL(request.url)
@sulmanweb
sulmanweb / _document.json.jbuilder
Created May 13, 2018
Active Storage as Attachment in Rails API with base64 decoding
View _document.json.jbuilder
json.extract! document, :id, :documentable_type, :documentable_id, :created_at
json.url rails_blob_url(document.doc)
@Aetherus
Aetherus / scale-out-phoenix-with-websocket.md
Last active May 24, 2022
How to scale out a Phoenix application with websocket
View scale-out-phoenix-with-websocket.md

How to scale out a Phoenix application with websocket

Foreword

It's relatively easy to scale out stateless web applications. You often only need a reverse proxy. But for those stateful web applications, especially those applications that embeds websocket services in them, it's always a pain to distribute them in a cluster. The traditional way is introducing some external services like Redis to handle pubsub, however, in such way, you often need to change your code. Can Erlang/Elixir, the "concurrency oriented programming languages", best other languages in this use case? Has Phoenix framework already integrated the solution of horizontally scaling websocket? I'll do an experiment to prove (or disprove) that.

Resources