Skip to content

Instantly share code, notes, and snippets.

View hopewise's full-sized avatar

Samir Sabri hopewise

View GitHub Profile
@hopewise
hopewise / create_rake_1_caller.config
Last active December 24, 2023 09:49
RubyOnRails cron jobs setup for AWS Elastic BeanStalk
# File: .ebextensions/create_rake_1_caller.config
files:
/tmp/run_cronjob_1.sh:
mode: "000755" # This sets the file as executable
owner: root # Set to the appropriate owner
group: root # Set to the appropriate group
content: |
#!/bin/bash
# Custom script content goes here
@hopewise
hopewise / gist:854efe65f4670146df2608e19b02754b
Created September 28, 2023 16:05
Log4j to log to a file
Using Log4j to log messages to a file involves a few steps:
1. **Add Dependencies**: If you're using Maven or Gradle, you need to add the required dependencies to your build file.
2. **Configure Log4j**: You need to create a Log4j configuration file (like `log4j2.xml`) to specify how logging should be handled, including sending log messages to a file.
3. **Use in Code**: Finally, you use Log4j in your Java code to log messages.
Let's go through each step:
@hopewise
hopewise / list_tables.rb
Last active February 23, 2023 08:53 — forked from davidleandro/list_tables.rb
Rails list all tables count
tables = []
ActiveRecord::Base.connection.tables.each do |t|
count = ActiveRecord::Base.connection.exec_query("select count(*) from #{t}").rows[0][0]
puts "#{t}, #{count.to_i}"
tables << [t, count.to_i]
end
tables.sort_by { |t| t[1] }.reverse!
puts "====================="
ap tables
@hopewise
hopewise / Dockerfile
Last active January 31, 2023 12:24
MySQL 5.7, asdf, Ruby 2.7.7
FROM mysql:5.7.37-debian
#install ruby
RUN apt update
RUN apt install -y git
RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.1
RUN . "/root/.asdf/asdf.sh"
RUN asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
RUN apt install -y wget
RUN apt-get -y install make
@hopewise
hopewise / gist:95db9d666c81e676307f86bd296d484a
Last active July 13, 2020 12:11
NGINX access.log analysis:
For NGINX:
Show analysis of access.log file
goaccess -f /var/log/nginx/access.log --log-format='%h %^[%d:%t %^] "%r" %s %b"%R" "%u" "%f" "%T" "%T" "%T" ' --date-format=%d/%b/%Y --time-format=%T
Show analysis of specific route:
tail -25000 /var/log/nginx/access.log.1 | grep /webhooks | goaccess --log-format='%h %^[%d:%t %^] "%r" %s %b"%R" "%u" "%f" "%T" "%T" "%T" ' --date-format=%d/%b/%Y --time-format=%T
For specific time: >= 5PM <= 8PM, date 12/Jul/2020
@hopewise
hopewise / install Taurus
Created May 1, 2020 13:16
Install Taurus at Ubuntu
#install python3.5
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
cd /usr/src
wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz
sudo wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz
sudo tar xzf Python-3.5.6.tgz
cd Python-3.5.6
sudo ./configure --enable-optimizations
sudo make altinstall
@hopewise
hopewise / test.rb
Created October 27, 2019 04:14
New Year Chaos, I don't know why it fails at case: `1 2 5 3 7 8 6 4` ?
#!/bin/ruby
require 'json'
require 'stringio'
# Complete the minimumBribes function below.
def minimumBribes(q)
too = false
bs = 0
@hopewise
hopewise / build.gradle
Created June 24, 2019 11:52
Build gradle without signing info to be used with MS App Center
repositories {
maven { url 'https://raw.github.com/applanga/sdk-android/master/maven/releases/' }
maven { url 'https://jitpack.io' }
}
buildscript {
repositories {
jcenter()
google()
maven {
@hopewise
hopewise / gist:0ac6a48b3502a42554ca5ba61dd258df
Created March 25, 2019 12:31
Extract all screen titles in sketch.cloud
#might need to change selector..
for (var i=0; i< $$(".sc-gacfCG").length; i++) console.log(i, $$(".sc-gacfCG")[i].textContent);
@hopewise
hopewise / copy_folder.rb
Created February 27, 2019 18:06
ruby method to copy from a folder to another folder within the same bucket
tested with `gem 'aws-sdk', '~> 2'`
```
@s3 = Aws::S3::Client.new(
region: ENV['AWS_REGION'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_KEY']
)