Skip to content

Instantly share code, notes, and snippets.

View revskill10's full-sized avatar
🎯
Focusing

Truong Hoang Dung revskill10

🎯
Focusing
  • Freelancer
  • Haiphong, Vietnam
View GitHub Profile
@revskill10
revskill10 / excel_generator.py
Created May 7, 2023 16:54 — forked from tnhu/excel_generator.py
Open and Edit an Excel template using Python's openpyxl library
from openpyxl import load_workbook
wb = load_workbook('template.xlsx')
# grab the active worksheet
ws = wb.active
# Data can be assigned directly to cells
ws['A2'] = 'Tom'
ws['B2'] = 30
Docker 23 + Traefik v2.9.10 and v1.7 + Let's Encrypt + Github Registry V2 ghcr.io + Updated on 12 April 2023
Content:
- Ubuntu 22.04
- Docker Engine 23.0.3
- Docker Compose 2.17.2
- Traefik v1.7.18 with dnsChallenge
- Traefik v2.9.9 with httpChallenge
--
- Github Registry V2 ghcr.io
@revskill10
revskill10 / useLocalStorage.ts
Created April 13, 2023 13:16 — forked from augustolazaro/useLocalStorage.ts
React hook to manage local storage changes
import * as React from 'react'
const originalSetItem = localStorage.setItem
localStorage.setItem = function() {
const event = new Event('storageChange')
document.dispatchEvent(event)
originalSetItem.apply(this, arguments)
}
const originalRemoveItem = localStorage.removeItem
localStorage.removeItem = function() {
@revskill10
revskill10 / deploy.md
Created February 28, 2023 09:51 — forked from intabulas/deploy.md
Deploying SurrealDB to Fly.io

These are the rough steps for getting a surrealdb instance running on fly.io and connecting to it. This is heavily based off of steps posted in the surrealdb discord by rvdende. View Origional Post.

These steps work just fine for the hobby (pay as you go) plan.

HEADS UP By default this will create an instance on a single shared cpu with 256m memory. This is pretty darn small to do anything but experiment, but its free. You can scale your instance to something more useable by visiting the https://fly.io/apps/<appname>/scale. Obviously scaling to larger instances will incur higher costs, please refer to fly.io pricing

Installing fly.io client

source: fly.io docs

@revskill10
revskill10 / stored_procedure_service.rb
Created January 17, 2023 07:46 — forked from ys/stored_procedure_service.rb
Execute stored procedure
class StoredProcedureService
def self.instance
@instance ||= StoredProcedureService.new
end
def execute(name, *args)
results = []
begin
connection.execute("CALL #{name}(#{args.join(',')})").each(as: :hash, symbolize_keys: true) do |row|
@revskill10
revskill10 / arel_helpers.rb
Created January 4, 2023 07:34 — forked from hadees/arel_helpers.rb
Arel Helpers
module ArelHelpers
extend self
def self.included(base)
base.extend self
end
def asterisk(arel_table_or_model)
arel_table, columns = case arel_table_or_model
when Arel::Table
@revskill10
revskill10 / gist:75052127a2ccb18d130fac034c705cb4
Created January 3, 2023 17:41 — forked from kbaribeau/gist:1103102
Ruby single quote escaping madness
Ok, so I'm trying to replace a ' character with \' in a ruby string. I have working code, but it was
*way* too painful getting there for my taste.
Take a look:
ree-1.8.7-2010.02 :001 > single_quote = "\'"
=> "'"
ree-1.8.7-2010.02 :003 > single_quote.gsub(/'/, "\\\'")
=> ""
ree-1.8.7-2010.02 :004 > single_quote.gsub(/'/) {|c| "\\'"}
@revskill10
revskill10 / rpc.rb
Created January 2, 2023 19:02 — forked from ahoward/rpc.rb
clean rpc based javascript helpers for rails' controllers
=begin
ref: https://gist.github.com/ahoward/5752290
web apps nearly always end up needing a plethora of little javascript helper methods: you know, auto-complete forms, populating defaults, validations, etc. these aren't API calls properly, just little tidbits of functionality needed to make the views work.
there is always a question of which controller to hang these methods off of. do you make a global helper controller for all this stuff? do you hang them off the controller in question? how to do share the backend of javascript helper methods across controllers?
step one
@revskill10
revskill10 / decorator.rb
Created December 30, 2022 13:56 — forked from masa16/decorator.rb
Decorator for Ruby similar to Python's decorator
module Decorator
@@decorators = []
def decorate(method_name,*args)
@@decorators << [method_name.to_sym,args]
end
def method_added(method_name)
super
return if @@decorators.empty?
decorators = @@decorators.reverse.map{|name,args| [method(name),args]}
@@decorators = []
@revskill10
revskill10 / SomeController.rb
Created December 16, 2022 14:18 — forked from ktkaushik/SomeController.rb
Using Prawn in your Rails App to download and attach the pdf in your email
require 'pdf_generator'
class TasksController < ApplicationController
include PdfGenerator
def some_action
pdf_generator( download = true )
end
end