Skip to content

Instantly share code, notes, and snippets.

@r3cha
r3cha / r-img_example
Last active April 2, 2019 09:49
place r-img tag in your html
<div class="image_area">
<r-img image-hash="hashWithImageUrls" bg-position="center">
</div>
@r3cha
r3cha / create_items.rb
Last active April 6, 2019 20:54
How to generate friendly urls without overhead of friendly id and etc.
# db/migrate/create_items.rb
# if you use activerecord
class CreateItems < ActiveRecord::Migration
def change
create_table :items do |t|
t.string :title
t.string :slug
t.timestamps
end
end
@r3cha
r3cha / Gemfile
Last active April 6, 2019 16:03
Create Ruby on Rails application from bootstrap theme
# add this gems to Gemfile
gem 'bootstrap', '~> 4.3.1'
gem 'jquery-rails'
gem 'popper_js', '~> 1.14.5'
FROM node:current-alpine3.11 as node
FROM ruby:2.6.5-alpine3.11 as build-base
COPY --from=node /usr/local/bin/node /usr/local/bin/
COPY --from=node /opt/yarn-v1.22.0 /opt/yarn-v1.22.0
RUN ln -s /usr/local/bin/node /usr/local/bin/nodejs
RUN ln -s /opt/yarn-v1.22.0/bin/yarn /usr/local/bin/yarn
RUN ln -s /opt/yarn-v1.22.0/bin/yarnpkg /usr/local/bin/yarnpkg
@r3cha
r3cha / user_jwt.rb
Last active May 27, 2020 09:23
Mongoid Rails model concern
# app/models/concerns/user_jwt.rb
module UserJwt
extend ActiveSupport::Concern
included do
include ActiveModel::SecurePassword
has_secure_password
field :email, type: String
field :phone, type: String
@r3cha
r3cha / docker-compose.yml
Last active September 4, 2020 10:58
Fastest way to up you frontend service
version: "3.8"
volumes:
node_modules:
services:
ui:
image: node:14.8.0-alpine3.12
ports:
- 3000:8080
@r3cha
r3cha / Dockerfile
Last active September 3, 2020 10:27
One app docker image for build frontend & backend
FROM node:14-alpine as node
FROM ruby:2.7.0-alpine3.11 as build-base
COPY --from=node /usr/local/bin/node /usr/local/bin/
COPY --from=node /opt/yarn-v1.22.4 /opt/yarn-v1.22.4
RUN ln -s /usr/local/bin/node /usr/local/bin/nodejs
# Here is you can copy npm from node to build-base if you preffer use it
RUN ln -s /opt/yarn-v1.22.4/bin/yarn /usr/local/bin/yarn
def perform(url)
return unless url
response = HTTParty.get(url)
return unless response.success?
data = JSON.parse(response.body)
return unless data['results']
data['results'].each do |test|
@r3cha
r3cha / deploy_compose.yml
Created August 5, 2024 09:58
Simple deploy using docker compose and reproxy
# NOTE: github actions at ./.github/workflows/ folder
# NOTE: generate ssh keypair at server, put pub key into authorized_keys at server and private key as SERVER github secrets
name: 'Build docker image, run tests and deploy'
on:
push:
jobs:
build:
name: Deploy docker-compose.prod.yml
@r3cha
r3cha / Dockerfile
Last active August 12, 2024 09:32
Dockerfile
FROM ruby:3.2.5-slim-bullseye AS development
COPY --from=node:20.16.0-bullseye-slim /usr/local/bin/node /usr/local/bin/
COPY --from=node:20.16.0-bullseye-slim /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node:20.16.0-bullseye-slim /opt/yarn-v1.22.22 /opt/yarn-v1.22.22
RUN ln -s /usr/local/bin/node /usr/local/bin/nodejs && \
ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \
ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx && \
ln -s /usr/local/lib/node_modules/corepack/dist/corepack.js /usr/local/bin/corepack && \