Skip to content

Instantly share code, notes, and snippets.

View leouofa's full-sized avatar
🏆

Leonid Medovyy leouofa

🏆
View GitHub Profile
// This code is to be used with https://turbo.hotwire.dev. By default Turbo keeps visited pages in its cache
// so that when you visit one of those pages again, Turbo will fetch the copy from cache first and present that to the user, then
// it will fetch the updated page from the server and replace the preview. This makes for a much more responsive navigation
// between pages. We can improve this further with the code in this file. It enables automatic prefetching of a page when you
// hover with the mouse on a link or touch it on a mobile device. There is a delay between the mouseover event and the click
// event, so with this trick the page is already being fetched before the click happens, speeding up also the first
// view of a page not yet in cache. When the page has been prefetched it is then added to Turbo's cache so it's available for
// the next visit during the same session. Turbo's default behavior plus this trick make for much more responsive UIs (non SPA).
@ryenski
ryenski / hello.vue
Last active April 27, 2023 03:04
Stimulus.js + Vue.js
<template>
<div id="app">
<p>{{ message }}</p>
</div>
</template>
<script>
export default {
data: function () {
return {
@andrewprogers
andrewprogers / reactRailsTestSetup.md
Last active October 9, 2018 23:26
Setting up A new React on Rails app with webpacker and full test suite

React on Rails with Test Suite (Karma, Jasmine, Enzyme, PhantomJS)

The steps included here detail the steps I followed to get a new React on Rails app set up, with a focus on testing JS components with Karma / Jasmine / Enzyme. A lot of this was liberally borrowed / modified from the Launch Academy curriculum, but there are some additional steps involved to get everything working with webpacker:

Unless otherwise specified, run the code in the terminal

Install Rails with Webpacker configured for React:

rails new project-name
cd project-name
@wbotelhos
wbotelhos / clear-sidekiq-jobs.sh
Last active April 2, 2024 10:04
Clear Sidekiq Jobs
require 'sidekiq/api'
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
@juliarose
juliarose / color.rb
Created August 12, 2015 13:01
Ruby color module - for blending two colors, lightening colors, and darkening colors.
module Color
def self.to_hex(c) # convert decimal to hex
n = c.to_i.to_s(16)
n = '0' + n unless n.length > 1 # 2 characters
n
end
def self.to_dec(c) # convert hex to decimal
c.to_i(16)
end
/**
* Imperavi Redactor Plugin for Embedding Tweets
* for version >= 9.1
*
* https://gist.github.com/jasonbyrne/6e96a907c781e90e0dbf
*
* @author Jason Byrne <jason.byrne@flocasts.com>
* @version 0.5.1
*
* @forked https://gist.github.com/chekalskiy/7438084
@pmarreck
pmarreck / actionview_helpers_texthelper_autolink_patch.rb
Created June 20, 2012 23:42
A monkeypatch to Rails' ActionView::Helpers::TextHelper (or that class provided by the rails_autolink gem) which causes it to chop up input data in case it's too long to handle
@eduardordm
eduardordm / Ability.rb
Created April 11, 2011 18:03
Ability Class, from ActiveRecord
# encoding: utf-8
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest
user.roles.each do |role|
role.permissions.each do |permission|
if permission.subject_class == 'all'
@shinzui
shinzui / tmux.conf
Created March 12, 2011 01:08 — forked from bryanl/tmux.conf
tmux.conf
# ~/.tmux.conf
#
# See the following files:
#
# /opt/local/share/doc/tmux/t-williams.conf
# /opt/local/share/doc/tmux/screen-keys.conf
# /opt/local/share/doc/tmux/vim-keys.conf
#
# URLs to read:
#