Skip to content

Instantly share code, notes, and snippets.

View khash's full-sized avatar
😷
Having fun!

Khash Sajadi khash

😷
Having fun!
View GitHub Profile
@khash
khash / component.html.erb
Last active March 5, 2023 05:48
Dropdown Component with ViewComponents, TailwindCSS and Stimulus
<!-- app/components/dropdown/component.html.erb -->
<div class="relative inline-block text-left" data-controller="dropdown--component">
<div>
<button type="button"
class="inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500"
data-action="click->dropdown--component#toggleMenu"
aria-haspopup="true"
aria-expanded="true">
<%= @title %>
<!-- Heroicon name: solid/chevron-down -->
@khash
khash / _stock.html.erb
Last active February 12, 2021 05:59
Rails Turbo Streams
<%= turbo_frame_tag dom_id(stock) do %>
<%= stock.ticker %> is <%= stock.price %>
<% end %>
@khash
khash / page.html.erb
Last active February 12, 2021 05:48
Slow Loading
<%= render 'fast_part' %>
<%= render 'slow_part' %>
@khash
khash / _show.html.erb
Created February 12, 2021 05:17
With Hotwire
<%= turbo_frame_tag :switch do %>
<%= button_to switch_path do %>
<%= switch.state %>
<%= hidden_field_tag :state, switch.state %>
<% end %>
<% end %>
@khash
khash / _show.html.erb
Created February 12, 2021 05:08
Rails No Hotwire
<%= button_to switch_path do %>
<%= switch.state %>
<%= hidden_field_tag :state, switch.state %>
<% end %>
@khash
khash / container.go
Created July 9, 2020 10:18
A simple template for a IoC in Golang
package utils
import (
"context"
"errors"
"fmt"
"sync"
)
type ObjectID string
@khash
khash / echo_zero_logger.go
Created July 9, 2020 09:47
Simple Echo middleware to log to Zerolog
// simple Echo middleware to log to Zerolog
package utils
import (
"time"
"github.com/labstack/echo"
"github.com/rs/zerolog"
)
{
"run": true
}
@khash
khash / nginx.yml
Created March 22, 2019 12:14
Nginx Ingress Controller
apiVersion: v1
kind: ServiceAccount
metadata:
name: nginx-ingress-serviceaccount
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: nginx-ingress-clusterrole
#!/bin/bash
__parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
__kube_ps1()
{
# Get current context
CONTEXT=$(cat ~/.kube/config | grep "current-context:" --color=NO | sed "s/current-context: //")