Skip to content

Instantly share code, notes, and snippets.

@cooljl31
cooljl31 / install_imagemagic_with_heic.sh
Created June 19, 2024 12:59 — forked from hurricup/install_imagemagic_with_heic.sh
How to install ImageMagick 7.1.0-54 with HEIC and WEBP support on Ubuntu 20.04
# inspired by https://gist.github.com/rjnienaber/af47fccb8410926ba7ea35f96c3b87fd
# remove bundled ImageMagick
sudo apt remove imagemagick -y
# install base dependencies
sudo apt-get install -y \
build-essential \
git \
libde265-dev \
@cooljl31
cooljl31 / classnamePrefixPlugin.ts
Created February 26, 2024 18:36 — forked from Anush008/gist:ffebc6ceb5439dc1ca2996ff7fb88311
Vite classname prefixer plugin
export function classnamePrefixPlugin() {
const prefix = 'tw-'
return {
name: 'classname-prefix',
transform: (code: string, id: string) => {
const classNamePattern = /(className|class)\s*(:|=)\s*"([^"]*)"/g
const transformedCode = code.replace(classNamePattern, (match, p1, p2, p3) => {
const transformedClassName = p3
.split(' ')
@cooljl31
cooljl31 / certbot-systemd-ubuntu.md
Created November 2, 2023 08:49 — forked from dbirks/certbot-systemd-ubuntu.md
Certbot renew with a systemd timer on Ubuntu

Ubuntu 16.04

/etc/systemd/system/certbot.service

[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet --agree-tos
@cooljl31
cooljl31 / converter.rb
Created July 5, 2023 08:24 — forked from ttilberg/converter.rb
Utilities to unobfuscate a certain class of js files.
require 'net/http'
require 'json'
require 'uri'
require 'yaml'
##
# Make a certain obfuscated js less obnoxious to analyze.
#
class Obfuscated
attr_accessor :script
#Simple form Input class for arrays
class ArrayInput < SimpleForm::Inputs::Base
def input(_wrapper_options)
#override the attribute name for arrays to allow rails to handle array forms
input_html_options.merge!({:name => "#{self.object_name}[#{attribute_name}][]"})
@builder.text_field(attribute_name, input_html_options)
end
end
@cooljl31
cooljl31 / debugging.rb
Created December 20, 2022 12:41
Create screenshot using Capybara and Selenium from debugging
page.driver.browser.manage.window.resize_to(1600, 1800)
page.save_and_open_screenshot('screen.png', full: true)
@cooljl31
cooljl31 / benchmark.rb
Created December 20, 2022 09:56
Benchmark example
Benchmark.ips do |x|
x.config(time: 30, warmup: 2)
x.report('gsub') { string.gsub(/ /, '') }
x.report('gsub, no regex') { string.gsub(' ', '') }
x.report('tr') { string.tr(' ','') }
x.report('delete') { string.delete(' ') }
x.compare!
end
import glob from 'fast-glob'
import nodeURL from 'url'
import process from 'process'
/** Returns pathnames matching the given pattern. */
const sync = (source: string) => glob.sync(source, options()) as string[]
/** Returns pathnames matching the given pattern. */
const async = (source: string) => glob(source, options()) as Promise<string[]>
@cooljl31
cooljl31 / migrate_hstore_to_json.rb
Created October 11, 2022 12:29 — forked from estum/migrate_hstore_to_json.rb
Ruby on Rails & Postgres: Reversible migrate hstore column to jsonb with contents
class MigrateHstoreToJson < ActiveRecord::Migration
def up
rename_column :posts, :data, :data_hstore
add_column :posts, :data, :jsonb, default: {}, null: false, index: { using: 'gin' }
execute 'UPDATE "posts" SET "data" = json_object(hstore_to_matrix("data_hstore"))::jsonb'
remove_column :posts, :data_hstore
end
def down
rename_column :posts, :data, :data_jsonb
@cooljl31
cooljl31 / google_script.js
Created June 22, 2022 12:14 — forked from shibulijack-fd/google_script.js
Google script to convert spreadsheet to YML
function getYAML() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dest = DocumentApp.openById(PropertiesService.getScriptProperties().getProperty("output_document_id"));
var key = Browser.inputBox("Please enter the key of the Google Spreadsheet containing the content to be generated as a YAML file.");
var source = SpreadsheetApp.openById(key);
var output = "---\nen:\n";
var sheets = source.getSheets();
for (var i = 0; i < sheets.length; i++) {