Skip to content

Instantly share code, notes, and snippets.

View wittawasw's full-sized avatar

Wittawas W wittawasw

View GitHub Profile
# First configure your models to use Amazon s3 as storage option and setup the associated S3 config.
# Then add the classes your want to migrate in the klasses array below.
# Then run rake paperclip_migration:migrate_to_s3
# Should work but this is untested and may need some tweaking - but it did the job for me.
namespace :paperclip_migration do
desc "migrate files from filesystem to s3"
task :migrate_to_s3 => :environment do
klasses = [:model_1, :model_2] # Replace with your real model names. If anyone wants to this could be picked up from args or from configuration.
klasses.each do |klass_key|
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/nginx.pid
@wittawasw
wittawasw / redis.md
Created August 22, 2016 22:08 — forked from diegopacheco/redis.md
How to Install Redis 3 Amazon Linux OS / CentOS

Install Redis cluster on Amazon Linux OS

sudo yum -y upgrade
sudo yum install -y gcc*
sudo yum install -y tcl
sudo wget http://download.redis.io/releases/redis-stable.tar.gz
sudo tar xzf redis-stable.tar.gz
cd redis-stable
cd deps ; sudo make hiredis jemalloc linenoise lua ; cd ..
@wittawasw
wittawasw / character_set_and_collation.rb
Created April 18, 2017 03:50 — forked from tjh/character_set_and_collation.rb
Convert all Rails table column collation and character set
#!/usr/bin/env ruby
# Put this file in the root of your Rails project,
# then run it to output the SQL needed to change all
# your tables and columns to the same character set
# and collation.
#
# > ruby character_set_and_collation.rb
DATABASE = ''
@wittawasw
wittawasw / readme.adoc
Created November 16, 2021 14:43 — forked from arun-gupta/readme.adoc
Federated Kubernetes Cluster using Kops on AWS

Let’s set up a federation between earth and mars Kubernetes cluster on AWS.

Earth cluster

  1. Create hosted zone:

    ID=$(uuidgen) && \
       aws route53 create-hosted-zone \
       --name earth.kubernetes-aws.io \
@wittawasw
wittawasw / app.rb
Last active March 17, 2022 17:31 — forked from runemadsen/app.rb
Sinatra File Upload
require 'sinatra'
get "/" do
erb :form
end
post '/save_image' do
@filename = params[:file][:filename]
file = params[:file][:tempfile]
require "onnxruntime"
require "mini_magick"
img = MiniMagick::Image.open("bears.jpg")
pixels = img.get_pixels
model = OnnxRuntime::Model.new("model.onnx")
result = model.predict({"inputs" => [pixels]})
p result["num_detections"]
@wittawasw
wittawasw / gist:b355310de8b98101d55a614cfebba910
Created May 22, 2023 00:00 — forked from ggilder/gist:1055684
Use Sinatra to serve static files from the current directory
ruby -e "require 'rubygems';require 'sinatra';set :port, 9999;set :public, Dir.pwd"
@wittawasw
wittawasw / updatefw.sh
Created September 15, 2023 12:21 — forked from selfagency/updatefw.sh
[update digital ocean firewall] update digital ocean firewall rules to add current ip and remove old external ips
# Requires doctl and the "public-ip-cli" npm module to be globally installed.
#!/bin/sh
FWID="YOUR_FIREWALL_ID"
IPV4=$("${HOME}/.nodebrew/current/bin/public-ip" --4)
#IPV6=$("${HOME}/.nodebrew/current/bin/public-ip" --6)
printf "🔥 Updating DO firewall rules\n\n"
OLD_RULES="$(doctl compute firewall get "${FWID}" --format InboundRules | tr ' ' '\n' | grep -E 'ports:22|ports:2022' | tr '\n' ' ' | sed '$ s/.$//')"