This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Server setup script for Ubuntu 22.04+ with Rails, Thruster, and Puma | |
| # Author: Muhammed Kanyi (@geniuskidkanyi) | |
| set -e | |
| echo "=== Rails + Thruster Deployment Server Setup ===" | |
| # Colors for output | |
| GREEN='\033[0;32m' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # LXC Student Environment Setup Script | |
| # Author: Muhammed Kanyi | |
| # Purpose: Create 13 isolated Linux containers for summer Linux course | |
| # Platform: Debian 12 (Bookworm) | |
| # Inspired by: Previous teaching experiences and passion for education | |
| set -e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Solution 1 Using Active Record Callbacks | |
| class YourModel < ApplicationRecord | |
| after_create :send_data_to_api | |
| private | |
| def send_data_to_api | |
| # Code to send data to the 3rd party API here | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # bookstore_spec.rb | |
| require 'rspec' | |
| class Bookstore | |
| attr_reader :books | |
| def initialize | |
| @books = [] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ArticleImageUploader < ImageUploader | |
| process :fix_exif_rotation | |
| process :strip | |
| process :convert => 'jpg' | |
| process :quality => 85 # Percentage from 0 - 100 | |
| version :gallery_thumb do | |
| process :resize_to_fill => Settings.images.article_images.processing.gallery_thumb #44x44 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Force non-www to www redirect | |
| if ($host !~* ^www\.) { | |
| rewrite ^(.*)$ $scheme://www.$host$1 permanent; | |
| } | |
| # Turn on SSL | |
| # protip: https://mozilla.github.io/server-side-tls/ssl-config-generator/ | |
| ssl on; | |
| add_header Strict-Transport-Security max-age=15768000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Force non-www to www redirect | |
| if ($host !~* ^www\.) { | |
| rewrite ^(.*)$ $scheme://www.$host$1 permanent; | |
| } | |
| # Turn on SSL | |
| # protip: https://mozilla.github.io/server-side-tls/ssl-config-generator/ | |
| ssl on; | |
| add_header Strict-Transport-Security max-age=15768000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def current_user | |
| current_user ||= Chatroom.find cookies.signed[:visitor_id] if cookies.signed[:visitor_id] | |
| if current_user | |
| current_user | |
| else | |
| visitor = Visitor.create!(location: "request.remote_ip", ip: "request.remote_ip") | |
| log_in visitor | |
| chatroom = Chatroom.create!(name: visitor.location) | |
| chatroom_user = chatroom.chatroom_users.where(user_id: visitor.id).first_or_create | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .txt-heading{padding: 5px 10px;font-size:1.1em;font-weight:bold;color:#999;} | |
| #product-grid {width:100%;display:flex;flex-flow:row wrap;} | |
| .txt-heading{background-color: #555;color:#FFF;} | |
| .product-item { | |
| width: calc(100% / 3) | |
| } | |
| .product-item div{text-align:center; margin:12px;} | |
| .product-price {color:#F08426;} | |
| .product-image {height:100px;width:130px;background-color:#FFF;} |
NewerOlder