Skip to content

Instantly share code, notes, and snippets.

View glaszig's full-sized avatar

glaszig

  • available for hire. contact me.
  • remote
View GitHub Profile
@mipearson
mipearson / elk.rb
Created July 5, 2018 06:07
Structured Logging with Rails & ELK example files
# Copyright 2018 Marketplacer. MIT License.
require 'json'
require 'active_support/core_ext/class/attribute'
require 'active_support/log_subscriber'
module Elk
class RequestLogSubscriber < ActiveSupport::LogSubscriber
PAYLOAD_KEYS_TO_COPY = %i{
controller
@anthonyeden
anthonyeden / simplistic-ffmpeg-streaming.py
Created May 28, 2018 11:46
Sending FFmpeg output to HTTP, via Python's Flash
"""
Streaming FFmpeg to HTTP, via Python's Flask.
This is an incredibly simple example, which will yield issues due to inconsistant input and output rates.
If you're going to use this, VLC works okay as a client.
You really need to move FFmpeg into a separate thread, which should help stream audio more consistantly to the HTTP client.
Example by Anthony Eden (https://mediarealm.com.au)
"""
from flask import Flask
@nerdinand
nerdinand / fixtures.rb
Last active April 18, 2019 06:10
Poor man's fixtures for hanami
#
# A quick and dirty fixture implementation for use with Hanami, RSpec and PostgreSQL.
# Fixtures will be loaded when the suite starts and will be reset using transactions
# to the same state after each test case.
#
# Supports associations like so (author has many books):
#
# # authors.yml
# rowling:
# name: J.K. Rowling
@grawity
grawity / README.md
Last active November 15, 2023 19:35
systemd Type=notify implementations

The official documentation is in the [sd_notify(3)][1] manual page.

Very short summary:

  1. Change your systemd service to Type=notify.
  2. Your daemon will receive an environment variable NOTIFY_SOCKET, which contains a path to an AF_UNIX socket.
    (If the first path byte is @, this means an "abstract" socket, and you should change the 1st byte to 0x00 before using.)
  3. The protocol consists of sending datagrams containing textual (UTF-8) status messages.
    Each message contains newline-separated KEY=value parameters.
  4. When the daemon is ready, it must send READY=1, and systemd will transition the service from "starting" to "running".
@maxneuvians
maxneuvians / bucket.ex
Last active June 11, 2023 04:07
Leaky Bucket GenServer in Elixir
defmodule LeakyBucket.Bucket do
@moduledoc """
Simulates a leaky bucket implementation
"""
use GenServer
@initial_amount 0
@increment_rate 1
@leak_rate 2
@leak_interval 500
@dittoalex
dittoalex / s3_read_only_policy.json
Created June 13, 2017 18:45 — forked from ramhoj/s3_read_only_policy.json
AWS IAM S3 read/write only policy
{
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
@danielctull
danielctull / ReplaceSegue.swift
Created March 7, 2017 10:15
A simple NSStoryboardSegue to replace the last view controller in a NSSplitViewController.
import Cocoa
class ReplaceSegue: NSStoryboardSegue {
override func perform() {
guard
let source = sourceController as? NSViewController,
let new = destinationController as? NSViewController,
(function ($$) {
// Open a console in your web browser and paste
// this entire script into it. This script doesn't
// phone home at any point, you have to do that
// manually. Still, give it a read.
// `Cmd + Opt + J` on Chrome
var user;
@ecleel
ecleel / db_fixtures_dump.rake
Last active January 21, 2024 10:25 — forked from iiska/db_fixtures_dump.rake
Rails 5: Dump Rails db to fixtures
# Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
#
# Optimized version which uses to_yaml for content creation and checks
# that models are ActiveRecord::Base models before trying to fetch
# them from database.
namespace :db do
namespace :fixtures do
desc 'Dumps all models into fixtures.'
task :dump => :environment do
models = Dir.glob(Rails.root + 'app/models/**.rb').map do |s|
@mattwelke
mattwelke / operations_controller.rb
Created November 22, 2016 21:06
Async Controller Actions in Ruby on Rails
# Full repo:
# https://gitlab.com/mwelke/rails-async-example
Future = Concurrent::Future
class OperationController < ApplicationController
def sync
ops = [1, 2, 3]
ops.each do |n|