Skip to content

Instantly share code, notes, and snippets.

View secretpray's full-sized avatar
🎯
Focusing

Aleksander secretpray

🎯
Focusing
View GitHub Profile
@secretpray
secretpray / Setup Redis (macOS).md
Created February 4, 2022 11:36
Redis setup on Mac OS

type below:

brew update
brew install redis

To have launchd start redis now and restart at login:

brew services start redis
@secretpray
secretpray / Migration_sample.md
Last active March 3, 2022 07:49
Rails Migration sample

Rails can generate a lot of things for you. Personally I use generate model often to quickly setup a new model, including test files and a database migration. In its simplest form it looks like this:

rails generate product

This will get you started with a naked Product model. To make things easier, you can also supply attribute names:

rails generate product name description:text 
@secretpray
secretpray / Flash like tailwind with Stimulus (Rails 7).md
Last active December 18, 2022 08:29
Flash like tailwind with Stimulus (Rails 7)
app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
  <head>
    <title>Turboapp</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
@secretpray
secretpray / Check user_signed_in? and Is_author in Turbo Stream.md
Last active January 29, 2022 09:09
Check user_signed_in? and Is_author in Turbo Stream broadcasts
  1. Generate Stimulus controller
bin/rails g stimulus object_author
  1. app/javascript/controllers/object_author_controller.js
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
@secretpray
secretpray / Modded gravatar for User model.md
Last active March 15, 2023 18:31
Modded gravatar for User model (Tailwind 2.x)
  1. Gemfile (bundle install)
```ruby
gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master' # optional!!! (only for use in seed.rb)
gem 'faraday' # optional!!! (only for use in seed.rb)
gem 'gravatar_image_tag', github: 'secretpray/gravatar_image_tag', branch: 'master'
gem 'hotwire-rails' # optional!!!
gem 'image_processing', '~> 1.2'
gem 'tailwindcss-rails', '~> 0.5.1' # optional!!!
```
@secretpray
secretpray / advance-tooltip
Last active October 27, 2021 16:47
Advance Tooltip
Advance Tooltip
---------------
// Timer 5 sec -> count = 5000
// stop timer -> running = false
var count = 5000,
running = true,
secondsNode = document.getElementById("seconds"),
millisecondsNode = document.getElementById("milliseconds"),
mOld,
mNew;

Algo 1

Before

git status
git add .
git commit
git push Stage_xx
git checkout main
git branch -D Stage_xx
@secretpray
secretpray / Install Bootstrap 5 without jQuery
Last active February 8, 2024 08:00
Install Bootstrap 5 with tooltip, popover and toasts in Ruby on Rails 6+ (without jQuery)
1) yarn add bootstrap
2) yarn add @popperjs/core
3.1) in folder 'app/javascript/' create new folder 'stylesheets':
mkdir app/javascript/stylesheets/
3.2) in new folder 'stylesheets' create file 'application.scss'
cd app/javascript/stylesheets/
touch application.scss
https://www.robinwieruch.de/react-hooks-fetch-data
useEffect(() => {
let didCancel = false;
async function fetchMyAPI() {
let url = 'http://something/' + productId;
let config = {};
const response = await myFetch(url);
if (!didCancel) { // Ignore if we started fetching something else