Skip to content

Instantly share code, notes, and snippets.

f60f5f8d4ed42971a29a1e36498006d89319d4976a18cbb5092c65ade0be1a044781c28502041f62c89f306903671ada5695f3f60f0cc1968f0483f207475543
@toksdotdev
toksdotdev / paint-brush-strike-through.css
Created October 4, 2019 18:58
Create a strike through effect of a paint brush across a portion of text.
strike.paint-brush {
position: relative;
text-decoration: none;
margin-left: -0.05em !important;
}
strike.paint-brush::after {
border-bottom: 0.225em solid #bbecf1;
margin-left: -15px !important;
border-radius: 70% 80% 40% 30%;
<script>
/**
* Save an item to the local storage.
*/
function saveToLocalStrorage(event) {
const formValue = event.val(); // pick the text the user entered into the form
const formName = event.name; // pick up the name of the input box from the event
localStorage.setItem(formName, formValue);
}
@toksdotdev
toksdotdev / secret-santa.py
Last active December 16, 2019 14:49
Give gifts to a group of people such that no family members (with same surname) should give gifts to each other.
class Person:
def __init__(self, firstname, lastname):
self._firstname = firstname
self._lastname = lastname
@property
def firstname(self):
return self._firstname
@property
@toksdotdev
toksdotdev / JobHandler.js
Last active March 1, 2020 18:12
Job queue handler abstraction
const Bull = use("Rocketseat/Bull");
const moment = require("moment");
const Redis = use("Redis");
/**
* Prepare queue configuration. Options provided overrides
* the field value of the default configuration.
*
* @param {object} [options]
*/
@toksdotdev
toksdotdev / gcloud-k8s-account-switch.sh
Created December 10, 2020 17:52
Setup GCloud & Kubernetes environment easily
PROJECT_ID=boringcompany
GCLOUD_K8_ZONE=us-central1-c
GCLOUD_K8_CLUSTER=production
gcloud auth login
gcloud auth configure-docker
gcloud config set project $PROJECT_ID
gcloud container clusters get-credentials $GCLOUD_K8_CLUSTER --zone $GCLOUD_K8_ZONE --project $PROJECT_ID
@toksdotdev
toksdotdev / port-forward-k8-pod.sh
Created December 10, 2020 17:59
Port forward k8 pod to local machine
NAMESPACE=production
POD_LABEL=app=core-service
HOST_PORT=8080
APP_PORT=3333
kubectl port-forward --namespace $NAMESPACE \
$(
kubectl get pod \
--namespace $NAMESPACE \
--selector="$POD_LABEL" \
  • What do Etcd, Consul, and Zookeeper do?
    • Service Registration:
      • Host, port number, and sometimes authentication credentials, protocols, versions numbers, and/or environment details.
    • Service Discovery:
      • Ability for client application to query the central registry to learn of service location.
    • Consistent and durable general-purpose K/V store across distributed system.
      • Some solutions support this better than others.
      • Based on Paxos or some derivative (i.e. Raft) algorithm to quickly converge to a consistent state.
  • Centralized locking can be based on this K/V store.
@toksdotdev
toksdotdev / k8-utils.sh
Last active July 30, 2021 10:18
Useful Kubernetes utils
# Scale deployments
DEPLOYMENT=traefik
NAMESPACE=kube-system
kubectl scale deploy $DEPLOYMENT --replicas=0 -n $NAMESPACE
# Fetch k8s secret for any namespace (you must be authorized to fetch the secet)
SERVICE_NAME=whoami
NAMESPACE=kube-system
@toksdotdev
toksdotdev / actix-run-async-as-sync.rs
Last active December 9, 2021 14:06
Run an async block of code synchronously in the current thread
use std::future::Future;
use actix_rt::Runtime;
/// Runs the provided future, blocking the current thread until the future completes.
///
/// A good use case for this would be initialising
pub fn run_sync<F>(future: F) -> F::Output
where
F: Future,