Skip to content

Instantly share code, notes, and snippets.

View meysampg's full-sized avatar
🖖
bit bit 0 bit

Meysam P. Ganji meysampg

🖖
bit bit 0 bit
View GitHub Profile
@meysampg
meysampg / proxy_pass_by_port.conf
Created November 16, 2019 09:22
Proxy pass subdomains to port -Nginx
server {
listen 80;
listen [::]:80;
server_name ~^(?<port>.+)\.my\.domain\.ir$;
error_log /var/log/nginx/sd_error;
access_log /var/log/nginx/sd_access;
auth_basic "Administrator Login";
@meysampg
meysampg / count_status_code_nginx_access_log.sh
Created December 21, 2019 15:10
Count HTTP response code based on Nginx access log
cat llb_access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -rn
@meysampg
meysampg / project_scope_module_import.py
Created December 29, 2019 12:41
Import modules of a project insde its scope
import os
import sys
# import the list of packages on parent as module
current_path = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(current_path, ".."))
# code from: https://stackoverflow.com/a/951846/1592247
def my_import(name):
mod = __import__(name)
@meysampg
meysampg / google_translate_api_sample.py
Created January 27, 2020 07:48
A snippet for fetching data from Google translate API
import requests
def trans(w, source="en", target="fa"):
url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl={0}&tl={1}&dt=t&q={2}".format(source, target, w)
resp = requests.get(url)
return resp.json()[0][0][0]
print(trans("khubi?"))
# خوبی؟
def occurrencesOfLang(lang: String, rdd: RDD[WikipediaArticle]): Int = {
rdd.aggregate(0)(
(ac: Int, a: WikipediaArticle) => ac + a.mentionsLanguage(lang).compare(false),
(ac1: Int, ac2: Int) => ac1 + ac2
)
}
@meysampg
meysampg / add_cloudflare_ips_to_ufw.bash
Created April 6, 2020 20:24
Add Cloudflare IP range list to UFW
for ip in $(curl -qs https://www.cloudflare.com/ips-v4); do ufw allow from $ip; done
{
"server":"0.0.0.0",
"server_port":80,
"password":"<PASSWORD>",
"timeout":300,
"method":"aes-256-gcm",
"plugin":"v2ray-plugin",
"plugin_opts":"server",
"user":"nobody",
"nameserver": "1.1.1.1",
@meysampg
meysampg / docker-daemon-proxy.sh
Created April 10, 2020 10:47
Pass Docker Daemon Traffics behind a proxy
mkdir /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://localhost:8123/"
Environment="HTTPS_PROXY=http://localhost:8123/"
systemctl daemon-reload
systemctl restart docker
package mypackage_name_space_or_sth_like_that
// some packages are imported here, but they're internally used and not related to kafka or spark
import org.apache.log4j.Logger
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession
import org.apache.spark.serializer.KryoSerializer
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.kafka.common.serialization.StringDeserializer
./bin/kafka-topics.sh --alter --zookeeper <BROKER_IP>:2181 --topic <TOPIC_NAME> --partitions <NEW_PARITION_NUMBERS>