Skip to content

Instantly share code, notes, and snippets.

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

Kash Sajadi khash

😷
Having fun!
View GitHub Profile
@khash
khash / app.js
Last active November 5, 2025 05:26
Cloud 66 Status Page Source Code
Handlebars.registerHelper('equal', function(lvalue, rvalue, options) {
if (arguments.length < 3)
throw new Error("Handlebars Helper equal needs 2 parameters");
if( lvalue!=rvalue ) {
return options.inverse(this);
} else {
return options.fn(this);
}
});
@khash
khash / component.html.erb
Last active August 5, 2024 21:09
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 -->
global
maxconn 4096
user haproxy
group haproxy
daemon
defaults
option dontlognull
retries 3
option redispatch
@khash
khash / tfl_status.coffee
Last active June 15, 2022 11:02
London Underground Status Widget
class Dashing.TflStatus extends Dashing.Widget
@khash
khash / gist:2594409
Created May 4, 2012 11:59
Changing default Rails 3 confirmation alert behaviour with a click-twice approach
// This goes in application.js
// Using this, the confirmation alerts on Rails 3.1 will be replaced with this behaviour:
// The link text changes to 'Sure?' for 2 seconds. If you click the button again within 2 seconds the action is performed,
// otherwise the text of the link (or button) flips back and nothing happens.
$.rails.confirm = function(message, element)
{
var state = element.data('state');
var txt = element.text();
if (!state)
@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