Skip to content

Instantly share code, notes, and snippets.

import { Controller } from 'stimulus'
export default class extends Controller {
static targets = ['overlay']
static values = {
hidden: Boolean
}
static classes = ['hidden', 'shown']
toggle () {
@paulozullu
paulozullu / Fix.MD
Last active August 15, 2023 20:50
DigitalOcean without internet

After almost two weeks since I raised this issue, I was finally able to resolve it. The problem occurred in the first place because different packages got uninstalled somehow when I rebooted. This includes cloud-init, ufw and landscape-common. There is probably more that I haven’t noticed yet. Let’s start with the internet connection, this is how I fixed it:

  • Step 1. I created file “/etc/udev/rules.d/70-persistent-net.rules” and added
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="b2:fe:09:35:6e:57", NAME="eth0"

as I mentioned previously. Note that MAC address used above can be found here: “/etc/netplan/50-cloud-init.yaml”

  • Step 2. Run “sudo reboot” and check that eth0 interface persists by running “ifconfig -a”
@andrewmcodes
andrewmcodes / Gemfile
Created July 11, 2020 21:25
HEY's Gemfile annotated with annotate_gem
# Generated with https://github.com/ivantsepp/annotate_gem/
ruby '2.7.1'
# Full-stack web application framework. (https://rubyonrails.org)
gem 'rails', github: 'rails/rails'
# Timezone Data for TZInfo (https://tzinfo.github.io)
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# ==== Action Text ====
@ireneybean
ireneybean / app.rb
Created August 3, 2019 21:05
Stimulus.js without a build system, but with babel, Sinatra
#...
get '/' do
haml :index, layout: false
end
#...
@hiteshkr
hiteshkr / Graylog02DarkTheme.css
Last active October 18, 2020 10:49
CSS for Dark theme for Graylog 02
@-moz-document url-prefix("https://graylog"), url-prefix("https://gettingstarted.graylog.org") {
body {
background-color: black;
color: #999;
}
h1, h2, h3, h4, h5, h6 {
color: #ddd;
}
svg {
background-color: #666;
order_code = 'ABCXXX'
variant_id = 123
variant_units = 3 # unidades a agregar
# encuentra pedido existente
order = shop.order(id: order_code) # si no existe, creamos una nueva
# construimos un array de line_items
# a partir de los items del pedido existente
# si es que la variante que queremos agregar
@matiasleidemer
matiasleidemer / paginate.rb
Last active January 8, 2018 14:34 — forked from be9/paginate.rb
kaminari + JSON API pagination helper
def paginate(scope, default_per_page = 20)
collection = scope.page(params[:page]).per((params[:per_page] || default_per_page).to_i)
current, total, per_page = collection.current_page, collection.total_pages, collection.limit_value
render json: [{
pagination: {
current: current,
previous: (current > 1 ? (current - 1) : nil),
next: (current == total ? nil : (current + 1)),
@javan
javan / direct-uploads.md
Last active January 29, 2023 10:58
Active Storage direct uploads

direct-uploads

rails/activestorage#81

// direct_uploads.js

addEventListener("direct-upload:initialize", event => {
  const { target, detail } = event
  const { id, file } = detail
@mankind
mankind / rails-jsonb-queries
Last active April 17, 2024 12:14
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@alfredkrohmer
alfredkrohmer / server.rb
Created August 23, 2016 19:07
Web Terminal for Docker container with Sinatra and Websockets
require 'sinatra'
require 'sinatra-websocket'
require 'docker-api'
require 'pty'
set :server, 'thin'
def new_state
{
lock: Mutex.new,