Skip to content

Instantly share code, notes, and snippets.

View devhero's full-sized avatar
😁

Andrea Parisi devhero

😁
  • devhero
  • Milan
View GitHub Profile
@sillvva
sillvva / qsZod.ts
Created August 24, 2022 01:34
Query String Parser with Zod
import qs from "qs";
import { ZodSchema } from "zod";
const parseObjectPrimitives = (obj: Record<string, any>): any => {
return Object.fromEntries(
Object.entries(obj).map(([k, v]) => {
if (typeof v === "object") return [k, parseObjectPrimitives(v)];
if (!isNaN(parseFloat(v))) return [k, parseFloat(v)];
if (v === "true") return [k, true];
if (v === "false") return [k, false];
@ruanbekker
ruanbekker / ship_logs_to_loki.py
Created May 27, 2022 14:34
Python Requests to ship logs to Loki API
#!/usr/bin/env python3
# docs: https://grafana.com/docs/loki/latest/api/#post-lokiapiv1push
import requests
import time
# variables
LOKI_USERNAME="x"
LOKI_PASSWORD="x"
LOKI_ENDPOINT="https://loki-api.example.com/loki/api/v1/push"
@zachary-russell
zachary-russell / sqoosh-image.sh
Last active August 7, 2022 13:37
Squoosh CLI Optimization
squoosh-cli --mozjpeg '{"quality":75,"baseline":false,"arithmetic":false,"progressive":true,"op timize_coding":true,"smoothing":0,"color_space":3,"quant_table":3,"trellis_multipass":false,"trel lis_opt_zero":false,"trellis_opt_table":false,"trellis_loops":1,"auto_subsample":true,"chroma_sub sample":2,"separate_chroma_quality":false,"chroma_quality":75}' actionvance-guy5aS3GvgA-unsplash.jpg
@devhero
devhero / ffmpeg cookbook
Last active January 19, 2023 10:56
ffmpeg cookbook
# rotate
ffmpeg -i input.mp4 -map_metadata 0 -c copy -metadata:s:v rotate="180" output.mp4
# extract subs from mp4
# https://superuser.com/questions/393762/how-to-extract-subtitles-from-mp4-and-mkv-movies
ffmpeg -i video.mp4 subtitle.srt
# convert audio (using vbr)
ffmpeg -i input.mkv -c:a libopus -b:a 256k -vbr 1 -af "channelmap=channel_layout=5.1" output.mkv

Redux WebSocket Middleware: Example

This Gist provides some code examples of how to implement WebSocket stream handling using a Redux middleware. Please be aware that this is only provided as an example and that critical things like exception handling have not been implemented.

A more complete version has been packaged, tested, and is available on GitHub as redux-websocket. This library has also been published to npm at @giantmachines/redux-websocket.

Middleware

This module represents the foundation of the middleware and implements the ideas presented above. The exported function is used during the creation of the Redux store (see the following snippet).

@devhero
devhero / lectures
Created May 31, 2016 07:36
lectures
https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
http://www.taimila.com/blog/ddd-and-testing-strategy/
@DamianEdwards
DamianEdwards / json-in-markdown.md
Last active June 2, 2023 17:20
JSON comments on GH

What happens if you tell GitHub it's JSON

{
  "hello": "world" // I want my comments!
}

Just tell GitHub it's JavaScript

{
@christiangenco
christiangenco / download_egghead_videos.md
Last active January 29, 2024 03:16 — forked from ldong/download_egghead_videos.md
download egghead videos
@maximum-pixels
maximum-pixels / paginate_helper.rb
Created November 26, 2015 15:05
This is a custom link renderer that will format the pagination bar with Bootstrap4 as well as AJAX (i.e. data-remote="true") to use jquery-ujs rails
module PaginateHelper
class PaginateJSLinkRenderer < WillPaginate::ActionView::LinkRenderer
def prepare(collection, options, template)
options[:params] ||= {}
options[:params]['_'] = nil
super(collection, options, template)
end
protected
def html_container(html)
@twoneks
twoneks / remote heroku
Created April 20, 2015 15:43
add remote heroku
# remote list
git remote -v
# add heroku app remote
heroku git:remote --app brenda-kp
git remote -v
# heroku https://git.heroku.com/brenda-kp.git
# rename local remote