Skip to content

Instantly share code, notes, and snippets.

@kevinhq
kevinhq / clean.sh
Created May 26, 2020 09:22 — forked from Iman/clean.sh
Free up disk space on Ubuntu - clean log, cache, archive packages/apt archives, orphaned packages, old kernel and remove the trash
#!/bin/sh
#Check the Drive Space Used by Cached Files
du -sh /var/cache/apt/archives
#Clean all the log file
#for logs in `find /var/log -type f`; do > $logs; done
logs=`find /var/log -type f`
for i in $logs
@kevinhq
kevinhq / Gemfile
Last active August 11, 2022 15:20
How to implement two-factor authentication for Rails app by using Devise gem, Google authenticator, and ActiveModel::Otp gem
gem 'devise', '~> 4.7.1'
gem 'active_model_otp', '~> 2.0.1'
gem 'rqrcode', '~> 1.1.2'
# http://stackoverflow.com/questions/4673391/why-doesnt-haml-check-find-this-glaring-syntax-error
haml -c newsletter.html.haml
haml --debug newsletter.html.haml 2> /dev/null | sed '$d' | ruby -c
@kevinhq
kevinhq / Dockerfile
Created February 22, 2021 03:10
Dockerfile for Ruby 2.3 on Gitpod
FROM ubuntu:16.04
RUN apt-get update
### base ###
RUN apt-get update && \
apt-get install -yq build-essential sudo vim wget links curl rsync bc git git-core apt-transport-https libxml2 \
libxml2-dev libcurl4-openssl-dev openssl sqlite3 libsqlite3-dev gawk libreadline6-dev libyaml-dev autoconf \
libgdbm-dev libncurses5-dev automake zlib1g-dev libgmp-dev libssl-dev libmysqlclient-dev libpq-dev gnupg2 && \
rm -rf /var/lib/apt/lists/*
@kevinhq
kevinhq / delete-likes-from-twitter.md
Created January 31, 2021 06:36 — forked from aymericbeaumet/delete-likes-from-twitter.md
[Recipe] Delete all your likes/favorites from Twitter

Ever wanted to delete all your likes/favorites from Twitter but only found broken/expensive tools? You are in the right place.

  1. Go to: https://twitter.com/{username}/likes
  2. Open the console and run the following JavaScript code:
setInterval(() => {
  for (const d of document.querySelectorAll('div[data-testid="unlike"]')) {
    d.click()
 }
@kevinhq
kevinhq / add_virtual_column_index_to_ahoy_events.rb
Created August 28, 2020 03:27
Virtual Column Index for ahoy_events table
class AddVirtualColumnIndexToAhoyEvents < ActiveRecord::Migration[6.0]
def up
ActiveRecord::Base.connection.execute (
'ALTER TABLE ahoy_events ADD properties_id INT AS (JSON_UNQUOTE(properties->"$.id")) STORED;'
)
ActiveRecord::Base.connection.execute (
'ALTER TABLE ahoy_events ADD INDEX (properties_id);'
)
end
def down
@kevinhq
kevinhq / application.html.erb
Last active August 15, 2020 18:03
Step-by-Step guide on how to move from Sprockets to Webpacker - application.html.erb
<%# app/views/layouts/application.html.erb %>
<!DOCTYPE html>
<html>
<head>
<!-- add this new application.js -->
<%= javascript_pack_tag 'application' %>
</head>
<body>
<%= yield %>
</body>
@kevinhq
kevinhq / application.js
Created July 9, 2020 06:09
Step-by-Step guide on how to move from Sprockets to Webpacker - updated application.js
/* app/javascript/packs/application.js */
require("@rails/ujs").start();
require("@rails/activestorage").start();
require("packs/example1");
require("packs/example2");
require("packs/example3");
@kevinhq
kevinhq / example2.js
Created July 10, 2020 04:55
Step-by-Step guide on how to move from Sprockets to Webpacker - packs/example2.js
/* app/javascript/packs/example2.js */
// to call example1 var, you need:
import example1 from './example1';
@kevinhq
kevinhq / example1.js
Created July 10, 2020 04:45
Step-by-Step guide on how to move from Sprockets to Webpacker - packs/example1.js
/* app/javascript/packs/example1.js */
var example1 = function doSomething() {
// Your codes here
}
export default example1;