Skip to content

Instantly share code, notes, and snippets.

View almokhtarbr's full-sized avatar
👋

almokhtar almokhtarbr

👋
  • 16:04 (UTC -04:00)
View GitHub Profile
@amirrajan
amirrajan / main.rb
Last active November 20, 2023 07:25
DragonRuby Game Toolkit - Shadows (https://amirrajan.itch.io/shadows) (https://youtu.be/wQknjYk_-dE)
# demo gameplay here: https://youtu.be/wQknjYk_-dE
# this is the core game class. the game is pretty small so this is the only class that was created
class Game
# attr_gtk is a ruby class macro (mixin) that adds the .args, .inputs, .outputs, and .state properties to a class
attr_gtk
# this is the main tick method that will be called every frame the tick method is your standard game loop.
# ie initialize game state, process input, perform simulation calculations, then render
def tick
defaults
@philsmy
philsmy / debug_rails.md
Created August 8, 2021 07:18
Debugging Ruby on Rails Cheatsheet
@hopsoft
hopsoft / Dockerfile
Last active May 17, 2023 19:58
Dockerize your Rails app
FROM ruby:3.0-alpine
RUN apk add --no-cache --update \
ack \
bash \
build-base \
curl \
git \
htop \
less \
@wakproductions
wakproductions / stonks-on-rails-3-rufus-vs-whenever.md
Created February 28, 2021 22:33
Rufus vs Whenever Ruby Schedulers - Stonks on Rails #3
# docker-compose.yml
version: '3'

services:
  web:
    build: ./
    command: 'rails server -b 0.0.0.0 -p 3000'
    ports:
      - 4000:3000
@miglen
miglen / packagejson.py
Created February 10, 2021 11:55
Dirty check for non existing public npm dependencies
#!/bin/env python3
# https://www.bleepingcomputer.com/news/security/researcher-hacks-over-35-tech-firms-in-novel-supply-chain-attack/
# The following script finds all package.json files in the current dir and checks if there are referenced any
# dependencies that no public package is available for, making your application vulnerable to supply-chain attack.
# Simply run ./packagejson.py in your root repository direcotory.
import json
import requests
from pathlib import Path
import urllib.parse
@dbreunig
dbreunig / qn.rb
Last active December 7, 2020 22:45
A script that creates a note with a specified, date stamped file name in a defined location, appends a divider and timestamp, then opens the file with TextEdit (macOS). This is what I'm reduced to now that Notational Velocity doesn't work so hot.
#!/usr/bin/env ruby
#
# qn stands for 'Quick Note.' This app quickly creates a text file
# in a hardcoded or specified directory with a default filename.
#
# The filename is {project}_YYYY-MM-DD.txt
#
# One file per day, per project is created. If the file exist, the
# new note is appended.
@dorner
dorner / table_controller.js
Last active February 22, 2024 10:03
Stimulus table controller
import { Controller } from "stimulus"
import $ from "jquery"
export default class extends Controller {
static targets = ["filter", "table", "pagination", "row"]
connect() {
this.page = Number(this.data.get("page")) || 1;
this.perPage = Number(this.data.get("per-page")) || 20;
@dalezak
dalezak / _form.html.erb
Last active April 15, 2024 12:13
Stimulus.js Toggle Controller to show and hide form elements based on select value
<div class="form-group">
<%= form.label :type, "Type", class: "font-weight-bold" %>
<%= form.select :type, ['TextQuestion', 'UrlQuestion'], { include_blank: true }, { class: "form-control", data: { action: "input->toggle#changed", target: "toggle.select" } } %>
</div>
<div class="form-group">
<%= form.label :name, "Name", class: "font-weight-bold" %>
<%= form.text_field :name, class: "form-control" %>
</div>
<div class="form-group" data-target="toggle.element" data-values="UrlQuestion">
<%= form.label :url, "URL", class: "font-weight-bold" %>
@crashtech
crashtech / RoR, from MVC to GraphQL.md
Last active May 29, 2023 22:42
RoR, from MVC to GraphQL

Ruby on Rails, from MVC to GraphQL

As a Ruby on Rails developer, I'm always looking for the best tools and practices to apply to my day-to-day development. This framework has a fantastic structure where all its inner parts communicate very well. But, as applications start growing, or developers want to start using more modern technologies, several things start getting out of control.

Recent versions of Rails implemented Webpack, facilitating the use of modern JavaScript frameworks, which added another level of robustness to everyone's applications. Not only is this becoming the new standard, but it also enables bigger code-bases without falling into madness.

Facebook, as the creator of ReactJS (one of these modern JS frameworks and the most popular one) introduced to the world another of its technologies, GraphQL. This tool, like any other tool, can be a great asset, as long as it's in the right hands, meaning that you first need to know what role it plays before exploring how to use it in your RoR appli

@leastbad
leastbad / README.md
Last active February 25, 2021 04:52
stimulus-websocket preview

This controller can be put on body or any other element.

  1. Adds a websocket accessor to the element
  2. Controller exposes a connected boolean getter
  3. Controller bails with a warning if no shared consumer is available
  4. Element will have data-action-cable-connected or data-action-cable-disconnected attributes which can be used for CSS selectors
  5. Element will emit action-cable:connected or action-cable:disconnected events only when state is flipping
  6. Errors => Disconnected to keep things simple

I intend to document the navigator.onLine accessor and the window:online/offline events so devs can handle PWA modes.