Skip to content

Instantly share code, notes, and snippets.

View khnshn's full-sized avatar
🎯

Alireza Khanshan khnshn

🎯
View GitHub Profile
@khnshn
khnshn / log_traceback.py
Last active June 24, 2018 11:03
Convey the exception traceback to into log file in python
#!/usr/bin/env python
import sys, traceback
def main():
number = 10
print(len(number))
if __name__=="__main__":
try:
@khnshn
khnshn / CustomTypeface.java
Last active June 24, 2018 11:04
Dynamic font size on Android devices
package helper;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;
public class CustomTypeface extends TypefaceSpan {
private final Typeface newType;
private final float size;
@khnshn
khnshn / send_email.py
Created June 27, 2018 14:33
Send smtp email programatically from python
import smtplib
gmail_user = 'email@example.com'
gmail_password = 'password'
message='Subject:{}\n\n{}'.format('my subject', 'my text')
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(gmail_user, ['receiver1@example2.com'], message)
server.close()
@khnshn
khnshn / Web.config
Created October 12, 2018 08:43
A simple config for custom HTTP Handlers in a ASP.Net Web Application project
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<add name="ImageHandler" verb="*" path="*.png" type="WebApplication1.Handlers.ImageHandler, WebApplication1"/>
</handlers>
</system.webServer>
<system.web>
@khnshn
khnshn / wireshark_commands.txt
Created November 11, 2018 10:56
Some wireshark commands I often use
ip.addr == x.x.x.x
ip.dst == x.x.x.x
ip.src == x.x.x.x
tcp.port == x
tcp.dstport == x
tcp.srcport == x
http or tcp.port == x
ip.addr == x.x.x.x && ip.addr == x.x.x.x
http.request
import requests
import multiprocessing
import time
import sys
from collections import Counter
def get_uris(uri):
session = requests.Session()
try:
response = str(session.get(uri).status_code)
@khnshn
khnshn / search.py
Created February 1, 2019 14:48
Simple search to look through all your codes for a keyword
import os
import sys
def search(p, s, ff):
try:
dirs = os.listdir(p)
for item in dirs:
if '.' in item:
if item.endswith('.{}'.format(ff)):
@khnshn
khnshn / send_notification.py
Created December 16, 2022 14:40
Sends notification to a list of smartwatches with Tizen OS given the message from the command line
import requests
import json
import time
import pandas as pd
import random
import sys
def send_notif(message):
@khnshn
khnshn / remove_git_history.txt
Created December 20, 2022 13:40
Removes the commits history and pushes the current files as the initial commit
git checkout --orphan latest_branch
git add -A
git commit -am "first commit"
git branch -D main
git branch -m main
git push -f origin main
git gc --aggressive --prune=all
select t2.* from (select json_extract(replace(value, "'",'"'),'$[*]') as arr from rh23_game_session inner join rh23_property_instance on rh23_game_session.id=rh23_property_instance.game_session where property_tk='PPG_LOG') as t1,
JSON_TABLE(cast(t1.arr as NCHAR), '$[*]' COLUMNS (
li INT PATH '$.li', ts BIGINT PATH '$.ts')
) t2