Skip to content

Instantly share code, notes, and snippets.

View garyharan's full-sized avatar
🎯
Focusing

Gary Haran garyharan

🎯
Focusing
View GitHub Profile
@garyharan
garyharan / _form.html.erb
Last active December 2, 2023 22:16
search select
<%= form_tag home_search_path, method: :get, data: { controller: "search" } do |form| %>
<div class="relative">
<div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
<svg class="w-4 h-4 text-gray-500 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z"/>
</svg>
</div>
<%= text_field_tag :q, params[:q], data: { "search-target": "query" }, class: "block w-full p-4 ps-10 text-sm text-gray-900 border border-gray-300 rounded-t-lg rounded-b-lg bg-gray-50 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500", placeholder: "Search", required: true %>
@garyharan
garyharan / best_practices.md
Created November 3, 2023 12:45
Ways to improve your coding practices

Best Practices when coding

Bring display logic down the line when you can

If your template has lots of ifs about what kind of models you have you may want to generisize the display portion.

One example is that instead of this:

class Car
@garyharan
garyharan / _mixins.scss
Created May 5, 2011 15:46
Useful scss mixins (rounded corners, gradients, text-field, button)
@mixin box-shadow($top, $left, $blur, $color, $inset: false) {
@if $inset {
-webkit-box-shadow:inset $top $left $blur $color;
-moz-box-shadow:inset $top $left $blur $color;
box-shadow:inset $top $left $blur $color;
} @else {
-webkit-box-shadow: $top $left $blur $color;
-moz-box-shadow: $top $left $blur $color;
box-shadow: $top $left $blur $color;
}
@garyharan
garyharan / uncommit_and_stash.sh
Created February 7, 2019 16:02
How to stash your unpushed commits
$ git status
5 commits pending
$ git reset --soft HEAD~5 # where 5 is the number of commits you saw in the `git status`
$ git stash
@garyharan
garyharan / java_installs.md
Created June 29, 2023 19:53
Figure out what versions of Java are installed on my Mac

Run the following: mdfind -name 'java' | grep '/bin/java$'

@garyharan
garyharan / back_to_the_tab.md
Last active March 1, 2023 18:02
RFC How to reopen existing tab

We need a way back to the tab when resetting passwords or getting a token from email or second factor authentication.

Too often we open a bunch of tabs and forget which one was open.

Imagine if we could create a token that would reopen the given tab that initiated the exit.

window.security.tabIdToken // returns: 35c7b72b-00bd-4734-81f7-318392f52370
@garyharan
garyharan / installation.md
Created February 1, 2023 14:49
How to install turbo-ios

Installing Turbo iOS on a Swift app

Add turbo-ios package

File > Add Packages > Paste in 'https://github.com/hotwired/turbo-ios/' > Add

Enable Cocoapods

First run sudo gem install cocoapods Then touch Podfile

@garyharan
garyharan / maximum_processes.ex
Created September 27, 2018 17:51
How to calculate maximum number of processes in Elixir
0..1_000_000
|> Enum.each(fn(_n) ->
IO.puts "Creating process: #{Process.list |> Enum.count}"
spawn(fn -> Process.sleep(:infinity)
end)
end)
@garyharan
garyharan / test_helper.rb
Created December 27, 2022 16:16
How to test using capybara in latest rails and chrome
# as per https://rubydoc.info/github/teamcapybara/capybara/master#using-capybara-with-minitest
require 'capybara/rails'
require 'capybara/minitest'
class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
# Make `assert_*` methods behave like Minitest assertions
include Capybara::Minitest::Assertions
@garyharan
garyharan / height_difference.md
Created December 19, 2022 17:01
ActiveRecord order by SQL generated value

If you want to create an extra attribute based on SQL query with ActiveRecord you can use the following:

@games = Game.select("*, ABS(#{@profile.level} - level) AS level_difference")

Then in your Ruby code you can refer to things this way:

@games.first.level_difference # =&gt; 16