Skip to content

Instantly share code, notes, and snippets.

module ImageProcessing
module MiniMagick
module Processing
extend ActiveSupport::Concern
included do
def watermark(scale: 0.15)
# ActiveStorage custom variant reference:
# https://stackoverflow.com/questions/71832729/how-do-i-create-a-non-trivial-activestorage-variant-for-watermarking-images
# https://round-tractor.medium.com/custom-image-variants-with-rails-active-storage-88d84ea007bc
@KevinSia
KevinSia / pillarbox-generation.bash
Created August 14, 2024 16:47
Generate image with pillarbox (like YouTube thumbnail) using ImageMagick
convert ori.jpg \
\( -clone 0 -blur 0x20 -resize "1350x800"\! -modulate 80,50,100 \) \
+swap -gravity center -compose over -composite test.jpg
import 'package:app/common_widgets/placeholders/loading_placeholder.dart';
import 'package:app/common_widgets/wrappers/system_notifs_permissions_wrapper.dart';
import 'package:app/feature/recent_notifications/application/recent_notifications_model.dart';
import 'package:app/feature/recent_notifications/presentation/recent_notifs_page/recent_notifs_scaffold.dart';
import 'package:app/feature/recent_notifications/presentation/recent_notifs_page/recent_notifs.dart';
import 'package:app/graphql/codegen/graphql_api.dart';
import 'package:app/utils/graphql_provider.dart';
import 'package:app/utils/sentry_exception.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
require 'prawn'
arr = HallSession
.joins(:check_in_sessions, :hall)
.group('check_in_sessions.hall_session_id, auditorium_halls.name, hall_sessions.start_at, hall_sessions.end_at, hall_sessions.id')
.select('auditorium_halls.name as hall_name, hall_sessions.start_at, hall_sessions.end_at, COUNT(*) as c')
.order('hall_name, start_at, end_at')
.map do |ci|
[
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hello</h1>
<button onclick="loadJS('https://embed.tawk.to/5fa44ae7fe038e7c95aa6e4d/default')">URL 1</button>
@KevinSia
KevinSia / main.rb
Last active September 26, 2019 10:20
Assessment
slips = {
"slip_23" =>
{
transactions: [123, 456],
shop: 1
},
"slip_42" =>
{
transactions: [789],
shop: 2

Intro to Rails

Sinatra vs Rails

  • Sinatra is lightweight
    • web app back end not just consists of business logic (turning your idea into logical code)
    • it also include app security, initialization/setup of the server, configurations, folder structure, front end files management and more
    • the sinatra folder structure you get is pre-made by someone else, sinatra itself doesnt restrict you in file and folder structure
      • while it gives freedom, it also means there are a lot of stuff you’ll have to configure (mailers, backend workers, integrating them together with your business logic)
    • Production env and development env is different
  • OS different
# generates a tic tac toe array with the right ratio of 'x' and 'o'
def generate_realistic_tic_tac_toe
# hardcode 4 'X's and 4 'O's, then pick one on random from ['X', 'O']
one_d = (%w(X X X X O O O O) << %w(X O).sample).shuffle
return one_d.each_slice(3).to_a
end
# turns the array of players into array of hashes
def convert_roster_format(roster)
header = roster.shift
# OLD SOLUTION
# def fibonacci_iterative(n)
# if n <= 1
# return n
# else
# arr = [0, 1]
# index = 0
# (n - 1).times do
# # arr might get very big if n is a big number
# arr << arr[index] + arr[index + 1]