* openssl req -newkey rsa:2048 -nodes -keyout myCompany.key -out myCompany.csr
* openssl x509 -signkey myCompany.key -in myCompany.csr -req -days 365 -out myCompany.crt
Tuesday, September 30, 2025
Generating your own certificate
Monday, July 21, 2025
Get versions of python modules installed
pip freeze | egrep 'pandas|pandas_market_calendars'
if you want to install a specific version:
pip install pandas_market_calendars==4.5.1
Wednesday, April 16, 2025
ssh banners
This command will output SSH banners from the server as pseudo-terminal is not allocated.
#!/bin/bash
ssh <user>@<server> << EOF
echo 'hi A'
EOF
In order to remove the banner, we can either change the command as follows:
#!/bin/bash
ssh <user>@<server> 'exec bash' << EOF
echo 'hi A'
EOF
or easiest way is
touch ~/.hushlogin
Tuesday, April 8, 2025
Zip file exploration
in data exploration, when you have a lot of zip files, you need a way to look at the cotents with extracting each zip file.
- zcat file.log.zip | less
- unzip -p archive.zip file1.txt | less
- vim archive.zip
Monday, April 7, 2025
VSCode (Not Visual Studio)
- Shortcuts:
- Ctrl+P - Open a file
- Ctrl+Alt+F - Search for a file in Explorer
- Extensions:
- Remote Explorer - SSH
- Git Lense - Git integration
- Data wrangler - Table view of data frames
- Zip Tools - Exploring zip files in a data set
- Windsurf / Codium - Auto Completion
- R-debugger via command line : install.packages("vscDebugger", repos = "https://manuelhentschel.r-universe.dev") # r-debugger vscode extension
Friday, February 21, 2025
Sending email from Python
Can setup SMTP inside python itself but for better protection, setup sendmail with SMTP as in other post and then:
Friday, February 14, 2025
Bloomberg BQL
BQL is not part of daily limit. So we can use those to get the data even when limit is hit:
=@BQL.QUERY("get(" & TEXTJOIN(",", TRUE, B1:E1) & ") for(members('RAY Index'))","cols=7;rows=5919")
where cells B1 to E1 have fields as follows:
market_cap px_volume 30_day_average_volume_at_time factor_expected_daily_volume
Thursday, February 13, 2025
Python Selenium Webdriver sample program
this is a sample program using selenium to click a button:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time
# Set up Chrome options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless") # Run in headless mode (no UI)
chrome_options.add_argument("--disable-gpu") # Disable GPU acceleration for headless mode
chrome_options.add_argument("--no-sandbox") # Disable sandboxing for headless mode
chrome_options.add_argument("--disable-dev-shm-usage") # Fix shared memory issues
# Set up ChromeDriver using Service (Selenium 4)
service = Service(ChromeDriverManager().install())
# Initialize WebDriver (Chrome) with the path to your ChromeDriver
driver = webdriver.Chrome(service=service, options=chrome_options)
try:
# Open the website
driver.get("http://omsprodapp:9900/oms/f#ListedWrapper")
# Wait for the page to load (you might need to adjust this)
time.sleep(5)
# Find the "Blotter All" button by its ID and click it
blotter_button = driver.find_element(By.ID, "blotAllButt")
blotter_button.click()
# Wait for the action to complete (adjust the sleep if needed)
time.sleep(2)
print("Successfully clicked 'Blotter All'!")
finally:
# Close the browser after the task is completed
driver.quit()
Wednesday, February 12, 2025
logger.sh
#!/bin/bash
Tuesday, February 11, 2025
Windows 11 Pro cannot grab window when maximized
Win + R -> "control access.cpl"
Make the mouse easier to use
UnCheck "Prevent windows from being automatically arranged"
Thursday, February 6, 2025
Loading env file in bash
If you want to load .env file before running a command in bash, we can use following utility. (Can use the just the command as well.)
14:54:00 harshal@HP:~$ set -a; source ~/.env; set +a; CMD
or
14:55:42 harshal@HP:~$ cat ~/load_dot_env.sh
set -a; source ~/.env; set +a
14:55:47 harshal@HP:~$ source ~/load_dot_env.sh
14:55:49 harshal@HP:~$
Wednesday, February 5, 2025
Citrix workspace on Ubuntu 2404
Typically, we start Citrix with this command:
/opt/Citrix/ICAClient/selfservice
But I was getting this error :
harsshal@HP:~$ /opt/Citrix/ICAClient/selfservice
/opt/Citrix/ICAClient/selfservice: error while loading shared libraries: libwebkit2gtk-4.0.so.37: cannot open shared object file: No such file or directory
But followed these steps and then it worked:
sudo add-apt-repository -y "deb http://gb.archive.ubuntu.com/ubuntu jammy main"
sudo apt update
sudo apt install libwebkit2gtk-4.0-dev
To enable middle click, Change the configuration file :
sudo vim /opt/Citrix/ICAClient/config/All_Regions.ini:
MouseSendsControlV=False
AutoHotKey programs
volume.ahk
#Requires AutoHotkey v2.0
Volume_Down::SoundSetVolume "-10"
Volume_Up::SoundSetVolume "+10"
Volume_Mute::SoundSetMute "-1"
mouse.ahk
#Requires AutoHotkey v2.0waitTime := 5 ; Number of minutes to wait
Loop {
Sleep waitTime * 60 * 1000
MouseMove 10, 0, 20, "R"
MouseMove -10, 0, 20, "R"
}
#Requires AutoHotkey v2.0 ; Ensure the script runs with AutoHotkey v2SetTimer RunCommand, 3600000 ; Set a timer to run every 1 hour (3600000 milliseconds)RunCommand(){currentTime := FormatTime("HH") ; Corrected FormatTime callif ((currentTime >= 7 and currentTime <= 15) or currentTime = 17) ; Check if it's between 7 AM - 3 PM or exactly 5 PM{Run("C:/Users/hpatil/AppData/Local/Microsoft/WindowsApps/python.exe c:/Users/hpatil/webdr.py")}}
or
#Requires AutoHotkey v2.0 ; Ensure the script runs with AutoHotkey v2
SetTimer RunCommand, 60000 ; Run every 60 seconds (1 minute)
RunCommand()
{
run_times := ["0715", "0815", "1000", "1340", "1500", "1700"] ; Define allowed times
currentTime := FormatTime(A_Now, "HHmm") ; Get current time in HHMM format
if HasVal(run_times, currentTime) ; Check if currentTime is in the array
{
Run("C:/Users/hpatil/AppData/Local/Microsoft/WindowsApps/python.exe c:/Users/hpatil/webdr.py")
}
}
HasVal(haystack, needle)
{
if !IsObject(haystack) ; Ensure it's an array before looping
throw Error("Bad haystack!") ; Use `Error` instead of `Exception`
for value in haystack
if (value = needle)
return true ; Return true if found
return false ; Return false if not found
}
Monday, January 27, 2025
Sending email via command line
sudo apt install mailutils
sudo apt-get install ssmtp
cat /etc/ssmtp/ssmtp.confmailhub=email.firm.com:25 <smpt server>
Then there are multiple ways to it
cat tempTo: harshal.patil@adyne.comSubject: Some Notifying EmailMIME-Version: 1.0Content-Type: text/plainBody of your email goes here. Hello world
cat temp | sendmail -i -t
echo -e "To: harshal.patil@firm.com\nSubject: Subject\nContent-type: text/html" | cat - /stage/qspc/projects/sas/tools/sas_slippage_outliers.html | sendmail -i -t
52 07 * * 1-5 echo "To: harshal.patil@firm.com, harshal.patil@firm.com \nSubject: Slippage Outliers $(date +\%F) \nContent-type: text/html\n\n" > /tmp/email_body.txt;cat /stage/qspc/projects/sas/tools/sas_slippage_outliers.html >> /tmp/email_body.txt;cat /tmp/email_body.txt | /usr/sbin/sendmail -i -t > /stage/qspc/logs/sendmail/$(date +\%d).log 2>&1
If wanted to attach as a file (when html contains graphs):
(cat /stage/qspcadmin/logs/sendmail/intraday_liquidation.header ; uuencode /stage/qspcadmin/projects/sas/tools/intraday_liquidation.html intraday_liquidation.html) | /sbin/sendmail -i -t
where
$ cat /stage/qspcadmin/logs/sendmail/intraday_liquidation.header
#To: harshal.patil@firm.com, a.b@firm.com
To: harshal.patil@firm.com
Subject: Intraday Strategy Liquidation
(echo "From: sender@example.com"echo "To: recipient@example.com"echo "Subject: Embedded Image"echo "MIME-Version: 1.0"echo 'Content-Type: multipart/related; boundary="boundary123"'echo ""echo "--boundary123"echo "Content-Type: text/html; charset=UTF-8"echo ""echo '<html><body>'echo '<p>Here is an embedded image:</p>'echo '<img src="cid:myimage" width="600" height="400">'echo '</body></html>'echo ""echo "--boundary123"echo "Content-Type: image/jpeg"echo 'Content-Transfer-Encoding: base64'echo 'Content-Disposition: inline; filename="image.jpg"'echo 'Content-ID: <myimage>'base64 image.jpgecho "--boundary123--") | sendmail -t
Python / pandas last_bday
import pandas as pd
from pandas.tseries.offsets import BDay
today = pd.to_datetime('today')
last_bday = today - BDay(1)
Thursday, January 23, 2025
Python groupby
There are 2 ways to normal results:
- use agg function
grp_df = df.groupby(['BookLevel4','Symbol','Direction','OrderId'], as_index=False).agg({'TxTime':['min','max','count'], 'FillQuantity':['sum']})
grp_df.columns = [''.join(col).strip() for col in grp_df.columns.values]
- use apply function
- In case you use more than 1 column
- Wont have to normalize multi-level columns
grp_df = df.groupby(['BookLevel4','Symbol','Direction','OrderId'], as_index=False).apply(
lambda s: pd.Series({
"TxTimemin": s["TxTime"].min(),
"TxTimemax": s["TxTime"].max(),
"TxTimecount": s["TxTime"].count(),
"FillQuantitysum": s["FillQuantity"].sum(),
"FillVWAP": (s['FillPrice'] * s['FillQuantity']).sum() / s['FillQuantity'].sum()
})
)
Tuesday, January 21, 2025
my .screenrc
All possible variables are listed here:
https://www.gnu.org/software/screen/manual/html_node/String-Escapes.html#String-Escapes
Here are the contents of my screenrc:
# Change default scrollback value for new windows
defscrollback 10000 # default: 100
# no welcome message
startup_message off
# advertise hardstatus support to $TERMCAP
termcapinfo * '' 'hs:ts=\E_:fs=\E\\:ds=\E_\E\\'
termcapinfo xterm* ti@:te@
vbell "off"
bindkey "^[OR" prev
bindkey "^[OS" next
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%H%? %1`%?%{g}][%= %{= kw}%-w%{+b yk} %n*%t%?(%u)%? %{-}%+w %=%{g}][%{B}%m/%d %{W}%C%A%{g}]'
screen -t notebook
screen -t local
Saturday, December 21, 2024
Docker commands
Was trying to create a docker for android. Here are the commands I used:
* sudo apt-get install qemu-kvm
* curl -fsSL https://get.docker.com -o get-docker.sh
* sh ./get-docker.sh
*docker run -d -p 6080:6080 -e EMULATOR_DEVICE="Samsung Galaxy S10" -e WEB_VNC=true --device /dev/kvm budtmo/docker-android:emulator_13.0
* sudo chmod 666 /var/run/docker.sock
(if permission denied in previous step)
* docker ps
* docker stop <NAME>
Tuesday, December 10, 2024
Date conversion in MySQL
With recent release, MySQL throws error when inserting dates. This is because, by default "strict mode" is enabled. To get rid of the errors, we need to do something as follows:
SHOW VARIABLES LIKE 'sql_mode';
set sql_mode='';
Friday, November 15, 2024
Installing IBC (Interactive Broker Controller)
This is a nice utility to keep ibkr TWS running. These are the commands :
$ wget https://github.com/IbcAlpha/IBC/releases/download/3.20.0/IBCLinux-3.20.0.zip
$ sudo unzip IBCLinux-3.20.0.zip -d /opt/ibc
$ sudo chmod o+x /opt/ibc/*.sh /opt/ibc/*/*.sh
$ cat ~/ibc/config.ini
IbLoginId=<username>
IbPassword=<password>
$ rm IBCLinux-3.20.0.zip
Friday, September 6, 2024
New Linux installation checklist
- sudo apt install ~/Downloads/google-chrome-stable_current_amd64.deb
- sudo apt-get install gnome-browser-connector
- sudo apt install libreoffice
- sudo apt install git-all
- ssh-keygen -t rsa
- sudo snap install code
- sudo apt install python3-venv
- python3 -m venv ~/.venv/ibkr_python
- https://extensions.gnome.org/extension/1160/dash-to-panel/
- Dash-to-panel settings (right click) -> ungroup applications
- settings -> system -> date/time -> show weekday
- Install vscode, extensions- python
Tuesday, September 3, 2024
git commands
git fetch
#!/bin/bashssh qspcadmin@USAZLINUXQSPCQ01 << EOFcd /stage/qspcadmin/projects/sasgit fetchgit pullgit add .git commit -m "Automated Commit"git pushEOF
Automated bashrc function to commit with good message:
function gpt_commit() {
diff=$(git diff)
response=$(curl -s -X POST https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"model": "gpt-4o-mini",
"messages": [
{
"role": "system",
"content": "You are an assistant that writes concise and informative git commit messages based on the provided git diff."
},
{
"role": "user",
"content": "$diff"
}
],
"temperature": 0.3
}
EOF
)
commit_message=$(echo "$response" | grep '"content":' | cut -d '"' -f 4)
echo "Generated commit message: $commit_message"
git commit -m "$commit_message"
}
Security cameras from desktop
Need to install ffmpeg in order to access rstp streams
* sudp apt install ffmpeg
Once it is installed, you can access the cameras via
* ffplay rtsp://hpatil:<pass>@<ip_address>:554/stream1
Monday, August 26, 2024
More than one ssh key for the github
* Generate new key:
[18:05:20 harsshal@dell:~/projects]$ ssh-keygen -t ed25519 -C "harsshal@gmail.com"
[18:07:35 harsshal@dell:~/projects]$ cat ~/.ssh/configTCPKeepAlive yesHost 10.234.1.112HostName 10.234.1.112User harshal# Default GitHubHost github.comHostName github.comUser gitIdentityFile ~/.ssh/id_rsaHost github-publicHostName github.comUser gitIdentityFile ~/.ssh/id_ed25519.pubHost github-personalHostName github.comUser gitIdentityFile ~/.ssh/id_ed25519
[18:09:02 harsshal@dell:~/projects]$ git clone git@github-personal:harsshal/icarus_gl.git
Friday, July 5, 2024
Jupyter notebook setup
jupyter notebook password
cat ~/.ipython/profile_default/startup/start.ipy
import os
import dotenv
dotenv.load_dotenv('/home/'+os.environ['LOGNAME']+'/.env',override=True)
import pandas as pd
# Pandas options
pd.options.display.max_columns = None
pd.options.display.max_rows = None
pd.options.display.max_colwidth = None
pd.options.display.float_format = '{:,.2f}'.format
print("Everything loaded")
jupyter notebook --notebook-dir [LOCATION] --no-browser --ip=192.168.255.X
jupyter nbconvert --execute --to html notebook.ipynb
Monday, June 3, 2024
Installing a module directly from repo
pip install git+https://github.com/blampe/IbPy.git
pip install git+https://github.com/atreyuxtrading/atreyu-backtrader-api.git
Friday, July 15, 2022
command line / bash variable in awk command
This is how we use a command line / bash variable (named num) in a awk command. We define an awk variable 'var' with -v option. This also shows use of BEGIN block.
awk -F, -v var=$num 'BEGIN{srand(var)} {print $1","$2","rand()}' file_name
Sunday, July 3, 2022
Change nameserver entries in resolve.conf
We can directly change the contents of the file but they dont seem to be in effect. So I added Google's nameserver in the file as follows :
$ sudo cat /etc/resolvconf/resolv.conf.d/base
nameserver 8.8.8.8
nameserver 8.8.4.4
And then updated the file as follows :
$ sudo resolvconf -u
we can also just update /etc/resolve.conf and it will be in effect immediately.
$ sudo sed -i '1 i\nameserver 8.8.8.8\nnameserver 8.8.4.4' /etc/resolv.conf
To remove the changes :
$ sudo sed -i '1,2d' /etc/resolv.conf
Wednesday, June 22, 2022
renaming all the files in a folder
IF we want to rename all the files with a part of the file we can do something following:
for file in $(ls); do nn=$(echo $file | awk -F'_' '{print($2)}'); mv $file $nn; done
Friday, March 11, 2022
shell loop through dates
Easy command to loop through the dates :
for i in 2022-01-{01..31} 2022-02-{01..15}; do echo $i; done
More comprehensive command :
d=2015-01-01
while [ "$d" != 2015-02-20 ]; do
echo $d
d=$(date -I -d "$d + 1 day")
done
Tuesday, October 27, 2020
tp-link archer t3u on ubuntu
Recently got tp-link T3u mini wifi adapter but as usual ubuntu did not have its drivers. So executed following commands and it worked perfectly.
cd /opt
git clone https://github.com/cilynx/rtl88x2bu.git
cd rtl88x2bu
VER=$(sed -n 's/\PACKAGE_VERSION="\(.*\)"/\1/p' dkms.conf)
sudo rsync -rvhP ./ /usr/src/rtl88x2bu-${VER}
sudo dkms add -m rtl88x2bu -v ${VER}
sudo dkms build -m rtl88x2bu -v ${VER}
sudo dkms install -m rtl88x2bu -v ${VER}
sudo modprobe 88x2bu
Monday, October 26, 2020
sudo access to ldap user
Typically, if you dont have sudo and "gain" sudo access, you cant just add yourself to sudo group. In that scenario, we need to reboot in "advanced mode" and gain access to root shell. Once in, you can have following :
$ sudo cat /etc/sudoers.d/hpatil
hpatil ALL=(ALL) ALL
and then we will have sudo access.
Thursday, February 20, 2020
Bootable USB
sudo dd bs=4M if=~/Downloads/ of=/dev/sdc1 status=progress oflag=syncyou can find out /dev/sdc1 via df command.
Highlight mouse with win + F5
sudo apt install libx11-dev libxcomposite-dev libxdamage-dev libxrender-dev
mkdir ~/git
cd git
git clone https://github.com/Carpetsmoker/find-cursor.git
cd find-cursor
make
echo "bindsym $mod+F5 exec /home/maahi/git/find-cursor/find-cursor -of" >> ~/.config/i3/config
docker commands
sudo echo 'deb https://apt.dockerproject.org/repo debian-stretch main' > /etc/apt/sources.list.d/dockertemp.listOnce installation was done, these were basic commands I used :
sudo apt-get update
sudo apt-get install docker-engine
sudo rm /etc/apt/sources.list.d/dockertemp.list sudo service docker start
https://sakuli.readthedocs.io/en/v1.0.0/docker-containers/
sudo docker pull harsshal/tws:first
sudo docker run -it -p 5901:5901 -p 8000:6901 harsshal/tws:first
sudo docker run -it -p 5901:5901 -p 8000:6901 -exec -u 0 harsshal/tws:first /bin/bash
sudo docker run -it -p 5901:5901 -p 8000:6901 -e "VNC_PW=ibtrader" harsshal/tws:first
sudo docker ps -a
sudo docker start
sudo docker commitharsshal/tws:second
sudo docker push harsshal/tws:second
sudo docker images
sudo docker ps -a | awk '{print $1}' | xargs sudo docker rm
Monday, December 16, 2019
Display all dataframe lines in ipython / jupyter notebook
import pandas as pd
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', 1000)
Wednesday, December 4, 2019
Vertica creating a temporary list of numbers
So rather than creating a table, I wanted to pass a list of numbers and see what happens. This is how I achieved it :
SELECT median(val) over() FROM (
SELECT * from (SELECT 1 as val, 1 as row
UNION SELECT 2, 2
UNION SELECT NULL,3
UNION SELECT NULL,4
UNION SELECT 4,5)temp
)temp2;
Thursday, November 7, 2019
i3 layout reload configuration
i3-save-tree > i3.jsonWe need to edit json file so that "class" entries in "swallows" sections are un-commented.
Enter following in config "~/.config/i3/config" :
exec load_i3_layout.shWhere as contents of the shell scripts are :
i3-msg 'workspace 1; append_layout i3.json'
i3-msg 'exec /usr/bin/chromium-browser'
i3-msg 'exec /usr/bin/dbeaver'
i3-msg 'exec /snap/bin/pycharm-community'
i3-msg 'exec /usr/bin/nautilus'
i3-msg 'exec /usr/bin/gnome-terminal'
i3-msg 'exec /usr/bin/chromium-browser'
Friday, October 12, 2018
awk delimiters
If its just space, we can use :
awk -F' ' '{print $2}'If its bunch of characters, we can use :
awk -F'[.:]' '{print $2}'
But with space, we need to use as follows :
awk -F'[[:space:].]+' '{print $2}'
I have not been able to figure out to associate '+' only to space. But for now this will server the purpose as long as I can combine multiple '.'
Some other classes are:
[[:blank:][:cntrl:]]
[ \t,:;]
Tuesday, September 25, 2018
Python notebook shortcuts
Ctrl + Enter : Execute current cell
Ctrl + / : multi-line comment
Ctrl + Shift + - : Split cell
Shift + m : Merge cells
a : Above current cell, create a cell
b : Below current cell, create a cell
Saturday, September 15, 2018
Linux mint suspend after more than 1 hour
- sudo apt-get install dconf-editor
- Open Menu->dcong-editor
- In dconf-editor, org > cinnamon > settings-daemon > plugins > power and manually set the value for the "sleep-inactive-ac-timeout" (it's in seconds)
Thursday, March 29, 2018
Installing new packages behind proxy
There are 2 main ways to do this :
pip install pandas
python -m pip install pandas --proxy proxy..com:3128
Second option has many other parameters which can be passed.
For installing via notebook, we can do as follows :
import sys
!{sys.executable} -m pip install numpy
!{sys.executable} -m pip list --user
Wednesday, March 14, 2018
Converting screen into tmux ( terminal multiplexer )
tmux which allows us to see multiple terminal windows at the same time. We can covert screen in doing something similar.
To split vertically: ctrl + a then |.
To split horizontally: ctrl + a then S (uppercase 's').
To unsplit: ctrl + a then Q (uppercase 'q').
To switch from one to the other: ctrl + a then tab
We can save layouts in screenrc so that we wont have to keep doing this as well.
Friday, February 23, 2018
Shell keyboard shortcuts
On Linux shell, imagine you are executing a long command and then you remember that you need to execute other command first.
Just found out an awesome feature where you can put a command in buffer (Ctrl+U), execute another command and then retrieve the buffer(Ctrl+Y).
Awesome!
Of course, Ctrl+A (Ctrl+A+A when you are in screen) to take you to the start of the line and Crtl+E to take you to end of the line.
Thursday, September 14, 2017
Linux mint buzzing sound when using headphones
- Open terminal and type
Alsamixer
- After that select the sound card (usually PCH)
- Go to far right until optiona
Auto-mute mode
- press up arrow to make it disabled.
Sunday, March 26, 2017
sqllite commandline history via up/down keys
worked like a charm for me.sudo apt-get install rlwraprlwrap sqlite3 database.db
Saturday, March 18, 2017
increasing brightness on LXDE display on lubunut
harsshal@dell:~$ ll /sys/class/backlight/
lrwxrwxrwx 1 root root 0 Mar 18 12:58 acpi_video0 -> ../../devices/pci0000:00/0000:00:02.0/backlight/acpi_video0/lrwxrwxrwx 1 root root 0 Mar 18 12:58 intel_backlight -> ../../devices/pci0000:00/0000:00:02.0/drm/card0/card0-LVDS-1/intel_backlight/
harsshal@dell:~$ ll /sys/class/backlight/*/max_brightness -r--r--r-- 1 root root 4096 Mar 18 12:58 /sys/class/backlight/acpi_video0/max_brightness-r--r--r-- 1 root root 4096 Mar 18 12:58 /sys/class/backlight/intel_backlight/max_brightness
harsshal@dell:~$ cat /sys/class/backlight/*/max_brightness 7255000
harsshal@dell:~$ echo 7 | sudo tee /sys/class/backlight/acpi_video0/brightness 7
harsshal@dell:~$ xbacklight -set 60
harsshal@dell:~$ xrandr -q | grep -w connectedLVDS-1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 290mm x 180mmharsshal@dell:~$ xrandr --output LVDS-1 --brightness 1
Wednesday, March 1, 2017
startup scripts in windows to keep screen active
set WshShell = WScript.CreateObject("WScript.Shell")
x = 1
do while x = 1 'Loop forever and ever and ever and ever
WshShell.SendKeys "%^" 'SEND CTL + ALT
WScript.Sleep 290000 '<5 MINS
loop
I placed this script at location
C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
and no more locking up the screen....
Tuesday, February 28, 2017
Adding right click options
vim ~/.gnome2/nautilus-scripts/terminalFor nemo, we need to have scripts at following locations:
/usr/share/nemo/actions/ for system-wide actions$HOME/.local/share/nemo/actions/ for user actionsType the command you want to have after right click. In this example, I do :
gnome-terminalAnd make that script executable:
chmod a+x ~/.gnome2/nautilus-scripts/terminal
Friday, January 6, 2017
Citrix receiver on linux version LUbuntu
usb-creator-gtkon my previous installation of linux mint.
Installation always used to hang on certain point on installer and could not figure out why. After googling, came to know that it needs network during installation but does not give any error. So connected LAN cable and got it installed.
First task was to make sure that no issues when connecting to office network. I installed receiver from
https://www.citrix.com/downloads/citrix-receiver.html
After installation, logged in and got an verisign ssl error. So did
sudo cp /usr/share/ca-certificates/mozilla/* /opt/Citrix/ICAClient/keystore/cacertsOne issue is chrome does not open citrix application right away. I need to open it via command line by executable located at
/opt/Citrix/ICAClient/wfica
Friday, May 22, 2015
Creating python executables
So these are the steps:
# Install "cx_Freeze"
# Create setup.py
$catsetup.py
from cx_Freeze import setup, Executable build_exe_options = { "includes": ['numpy', 'pandas','matplotlib.backends.backend_qt4agg'], "packages": [], "excludes": ['tk','ttk','zmq','boto','tkinter','_gtkagg', '_tkagg', 'bsddb', 'curses', 'pywin.debugger','pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 'Tkconstants', 'Tkinter'], "include_files": []} setup( name = "appName", version = "0.1", description = "", author = "Dengar", options = {"build_exe": build_exe_options}, executables = [Executable("sectorize.py")] )#python setup.py build
Tuesday, May 19, 2015
Alt+Tab not working in remote desktop of citrix receiver on Linux mint 17
I found this file in installation directory of ICAClient:
Went to link and started edited this file
[17:43:43 harsshal@lenovo:~]$ ll /opt/Citrix/ICAClient/config/All_Regions.ini
lrwxrwxrwx 1 root root 37 Nov 8 2013 /opt/Citrix/ICAClient/config/All_Regions.ini -> /etc/icaclient/config/All_Regions.ini
[17:44:08 harsshal@lenovo:~]$ sudo vim /etc/icaclient/config/All_Regions.ini
Search for "TransparentKeyPassthrough" in "Virtual Channels" section and add "Remote" in front of it.
[Virtual Channels\Keyboard]
TransparentKeyPassthrough=Remote
Wednesday, April 8, 2015
Google CodeJam in python templates
Following program is for http://code.google.com/codejam/contest/351101/dashboard#s=p2
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 7 15:40:09 2015
@author: hpatil
"""
import sys
def read_file( input_file, output_file):
sys.stdin = open(input_file)
if(output_file != '' ):
sys.stdout = open(output_file,"w+")
read_input()
def solver(line):
last_digit=10
for i in line:
#print(i)
#print(len(line))
digit, mystring = digit2string(i)
if(last_digit==digit):
print(' ',end='')
print(mystring,end='')
last_digit=digit
print()
return
def digit2string(char):
dial = [
[' '],
[],
['a','b','c'],
['d','e','f'],
['g','h','i'],
['j','k','l'],
['m','n','o'],
['p','q','r','s'],
['t','u','v'],
['w','x','y','z'],
]
mystring = ""
for digit in range(len(dial)):
for repeat in range(len(dial[digit])):
if(char==dial[digit][repeat]):
for times in range(repeat+1):
mystring+=str(digit)
return digit,mystring
def read_input():
with sys.stdin as file:
testCases = int(file.readline())
for test in range(testCases):
print("Case #{}: ".format(test+1), end="")
line = file.readline().strip('\n')
solver(line)
#read_file('input','')
read_input()
This one is for with integer reading for http://code.google.com/codejam/contest/351101/dashboard
# -*- coding: utf-8 -*-
__author__ = 'hpatil'
import sys
def show_graph(x,y):
import matplotlib.pyplot as plt
plt.plot (x, y)
plt.grid(True)
plt.show()
def solver(credit, nItems, items):
for i in range(nItems):
for j in range(i+1,nItems):
sum = items[i] + items[j]
if( sum == credit):
print(i+1,j+1)
return
def set_io( input_file, output_file):
sys.stdin = open(input_file)
sys.stdout = open(output_file,"w")
def read_input():
with sys.stdin as file:
testCases = int(file.readline())
for test in range(testCases):
print("Case #{}: ".format(test+1), end="")
credit = int(file.readline())
nItems = int(file.readline())
items = list(map(int,file.readline().split()))
show_graph(range(len(items)), items)
solver(credit, nItems, items)
set_io('input','out')
read_input()
Following program is for http://code.google.com/codejam/contest/3214486/dashboard which took me a loooooong time
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 8 13:08:15 2015
@author: hpatil
Solution to problem : http://code.google.com/codejam/contest/3214486/dashboard
"""
lit = [
#['abcdefg']
'1111110',
'0110000',
'1101101',
'1111001',
'0110011',
'1011011',
'1011111',
'1110000',
'1111111',
'1111011'
]
def display_calci(string):
if(string=="ERROR!"):
print(string)
else:
display = list(" ")
print(''.join(display))
# line 1
if(string[5] =='1'):
display[0]='|'
if(string[0] =='1'):
display[1]='^'
if(string[6] =='1'):
display[2]='_'
if(string[1] =='1'):
display[3]='|'
display[4]='\n'
if(string[4] =='1'):
display[5]='|'
if(string[3] =='1'):
display[6]='_'
display[7]='_'
if(string[2] =='1'):
display[8]='|'
print(''.join(display))
def isDigitFeasible(active, disp_digit, digit):
for led in range(7):
if(active[led]=='1'):
if( disp_digit[led] != lit[digit][led]):
return 0
return 1
def get_active_leds(active, disp_digits):
active= list(active)
count = int(disp_digits[0])
for digit in range(1,count+1):
for led in range(len(disp_digits[digit])):
if(disp_digits[digit][led]=='1' ):
active[led]='1'
return ''.join(active)
def led_unused(active, disp_digits, possible_digit):
not_used = list('1111111')
active= list(active)
count = int(disp_digits[0])
for digit in range(1,count+1):
possible_digit= (possible_digit+1)%10
for led in range(len(lit[possible_digit])):
if(lit[possible_digit][led]=='1' ):
not_used[led]='0'
return ''.join(not_used)
def print_digit(active, disp_digits, digit):
result_string = ""
unused = led_unused(active, disp_digits, digit)
for led in range(len(active)):
if(active[led]=='1'):
result_string += lit[digit][led]
else:
if(lit[digit][led] == '1'):
if(unused[led]=='1'):
return "ERROR!"
else:
result_string += '0'
else:
result_string += '0'
return result_string
def get_possible_digits(active, disp_digit, possible):
possible_return = [ ]
for digit in possible:
if(isDigitFeasible(active, disp_digit, digit)):
possible_return.append(digit)
return possible_return
def solver(disp_digits):
active= list('0000000')
active = get_active_leds(active,disp_digits)
if(debug):
display_calci(active)
count = int(disp_digits[0])
possible = [9,8,7,6,5,4,3,2,1,0]
for digit in range(1,count+1):
possible = get_possible_digits(active,disp_digits[digit], possible)
possible = list(map(lambda x: (x-1) % 10, possible))
if(debug):
print(possible)
possible_soln = list(map(lambda x: print_digit(active,disp_digits,x), possible))
if(debug):
print(possible_soln)
soln_set = set(possible_soln)
if(len(soln_set) != 1):
return "ERROR!"
else:
return list(soln_set)[0]
def read_input():
with sys.stdin as file:
nTests = int(file.readline())
for tests in range (1, nTests+1):
print("Case #" + str(tests)+": ", end="")
disp_digits = file.readline().split('\n')[0].split(' ')
if(debug):
print(disp_digits[1:])
list(map(lambda x: display_calci(x), disp_digits[1:]))
print("-----------")
answer_string = solver(disp_digits)
if(debug):
display_calci(answer_string)
print(answer_string)
import sys
debug = int(sys.argv[1])
sys.stdin = open (sys.argv[2])
#sys.stdin = open ('input2')
#sys.stdin = open ('A-small-practice.in')
#sys.stdin = open ('A-large-practice.in')
read_input()
Friday, March 6, 2015
Wake on by USB devices on Linux mint 17
I realized that Linux mint doesn't support wake on USB mouse / keyboard out of the box. so I created following file and it started supporting wake on USB devices again.
[01:35:11 harsshal@dell:~]$ cat /etc/udev/rules.d/90-keyboardwakeup.rules
#idVendor and idProduct taken from 'lsusb'
SUBSYSTEM=="usb", ATTRS{idVendor}=="0461", ATTRS{idProduct}=="4d15" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'"
SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", ATTRS{idProduct}=="2002" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'"
SUBSYSTEM=="usb", ATTRS{idVendor}=="413c", ATTRS{idProduct}=="1002" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'"
PS: When I rebooted machine, for some reason, my idProduct was changed. So if these don't work after reboot, make sure numbers are correct using "lsusb" again.
Wednesday, November 28, 2012
ctrl+left/right arrow by inputrc
1. On your console, press Ctrl + v - Ctrl + RightArraow. It should either print ^[0D or ^[[D.
2. Replace initial "^[" by "\e" and put it in ~/.inputrc as follows
"\e[D": forward-word
3. Restart session or press Ctrl x - Ctrl r . Confirm binding by
bind -P
Make sure your "env" has TERM=linux. (Putty -> Connection -> Data -> terminal-type string= linux)
Final ~/.inputrc should look like :
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
"\e[1~": beginning-of-line # Home key
"\e[4~": end-of-line # End key
"\e[5~": beginning-of-history # PageUp key
"\e[6~": end-of-history # PageDown key
"\e[3~": delete-char # Delete key
"\e[2~": quoted-insert # Insert key
"\eOD": backward-word # Ctrl + Left Arrow key
"\eOC": forward-word # Ctrl + Right Arrow key
Monday, October 15, 2012
Tabbed vim
vim -p < file1 > < file2 >
You can see that you can open multiple files and go to next file without saving (something you cannot do in multiple buffer). Youcan switch between files using tabn/tabp, but I do it as follows and use F5/6.
:map <f5> :tabp <cr>
:map <f6> :tabn <cr>
Thursday, May 10, 2012
Shell commands in VIM
:%! sed G Double space the entire file.
:1,5! sed G Double space the lines from 1-5.
Sunday, April 1, 2012
Downloading flash videos in ubuntu
$ cat ~/Dropbox/new_installation/scripts/flash_vid.sh #!/bin/bashnum=1;for FILE in $(lsof -n | grep "Flash.*deleted" | awk '{printf "/proc/" $2 "/fd/"; sub(/[a-z]+/,"",$4); print $4}'); do cp $FILE $HOME/Desktop/$num.flv size=$( stat -c %s $HOME/Desktop/$num.flv); if [ $size -gt 5000000 ]; then num=$[$num + 1]; else rm $HOME/Desktop/$num.flv; fidoneThursday, March 15, 2012
CVS important commands
cvs commit -m "my comment < filename >
cvs update < filename >
cvs -j < what version you want cvs to think it has > -j<what version you want cvs to go to > < filename >
Tuesday, March 13, 2012
linux commandline mail from shell as attachement
(cat mailtext; uuencode surfing.jpeg surfing.jpeg) | mail sylvia@home.com
uuencode $ATTFILE $ATTFILE | mail -s "$SUBJECT" $MAILTO
echo "hi" | mutt -a $ATTFILE -s "$SUBJECT" $MAILTO
Tuesday, November 22, 2011
mysqldump
insert into table1 select * deom database2.table2;
But they are not on the same host you can use following :
$ mysqldump -h host_name -u user_name -p database table_name "--where= date = 20111121" > temp
We can use "-t" option which will exclude table creation definition from the output.
Thursday, September 1, 2011
Finding latest modified file/directory
$ find . -exec stat \{} --printf="%y %n\n" \; | sort -n -r | head -1
$ for i in `ls`; do echo -n $i" "; find $i -exec stat \{} --printf="%y %n\n" \; | sort -n -r | head -1;done
Sunday, August 14, 2011
Mysql Tricks
- How to get current time
select now();
select curdate();
select curtime();
- How to get date in standard format
select date from table;
will give answer as "2011-08-15"
But
select date+0 from table;
will give answer as "20110815"
- To use group by with a summary.
select col from .... group by col with rollup;
This will give a summary(addition) in the last row.
- When performing string operations
Shell "*" => mysql "%"
Shell "?" => mysql "_"
- Conditional statements in mysql
select (sum(case when shares>0 then shares else - end) from table;
- Case-sensetive comparison
select 'A' like 'a';
1
select 'A' like binary 'a';
0
- Using variables
set @total=0;select (@total := 2+@total) as total from table;
- Checking table sizes
select table_schema "Database name", sum(data_length _ index_length)/1024/1024 "size", sum (data_free)/1024/1024 "Free space " from information_schema.TABLES group by table_schema;
- Command line execution and output
bash# mysql -e "select * from table";
mysql> select * into outfile "/tmp/hpatil" from ...;
But watchout for mysqld host and users when searching for outfile on commandline.
Thursday, July 14, 2011
Linux/Unix NFS bug
To solve this issue,
We need to create a temp file.
mv to original file
and then delete this file.
Now, we will be able to create a new file in same location.
Friday, July 8, 2011
Finding database size through mysql query
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;
My bashrc
PATH=$PATH:.:~/hpatil/0/export EDITOR=/usr/bin/vim
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\t \[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
export HISTSIZE=10000
export HISTCONTROL=erasedups
shopt -s histappend
BC_ENV_ARGS=~/.bcrc
export BC_ENV_ARGS
export INPUTRC=~/.inputrc
#alias vim="vim -c 'set nopaste'"
alias ll="ls -l"
alias rl="readlink -f"
alias vim='vim -c"set nopaste" '
alias vr='vim -MR -c"set nopaste" 'alias li='less -niFX'
alias grep_dir='_(){ bd;grep -a "mt=j" app.$1.tlog | grep -av "not active" | li;}; _'
function mailme() { (echo "Attached file: $1"; uuencode "$1" "$(basename "$1")") | mail -s "File: $(basename "$1")" harshal.patil@email.com}
function bc() { command bc -l <<< "scale=6; $*"}Tuesday, June 28, 2011
Setting autofs timeout option
OPTIONS="--timeout=86400"
Friday, June 24, 2011
Compression bzip2 command
find ./04 -type f | grep -v bz2 | xargs bzip2
Wednesday, June 9, 2010
Friday, April 30, 2010
Best way to get IE on ubuntu
sudo apt-get install wine
sudo apt-get install cabextract
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-2.99.0.1.tar.gz
tar xzvf ies4linux-2.99.0.1.tar.gz
./ies4linux-2.99.0.1/ies4linux
ln /root/bin/ie6 /usr/bin/ie6
ie6
And nice IE for testing...
Tuesday, April 27, 2010
popup=popup, not popup=newtab
Change:
browser.link.open_newwindowMine was set to 3, which told the popups to always open in a new tab. I like that, mostly. But some web sites, TinyMCE editor in this case, like to open a popup and return you back the the original page. I keep losing that original popup. So I wanted to turn off my popup forced to new tab option. To make this behave normally, I set it to 2. All worked just peachy!
Monday, April 19, 2010
Disabling touchpad while typing
cat >> /etc/hal/fdi/policy/shmconfig.fdi << END
<?xml version="1.0" encoding="UTF-8"?>
<deviceinfo version="0.2">
<device>
<match key="input.x11_driver" string="synaptics">
<merge key="input.x11_options.SHMConfig" type="string">True</merge>
</match>
</device>
</deviceinfo>
END
In start-up programs, add command
syndaemon -i 1 -d
and reboot!!!
Thursday, April 15, 2010
Listing files by decreasing directory size / space left
If you want to see how is your disk being used, you can use
du -s * | sort -k 1 -rnIf you want to see hidden files,
du -s .* | sort -k 1 -rnUnfortunately, I couldn't combine both of them and also couldn't use -h option of du
If you want to see size of different partition, you can also use
df -h
Monday, April 12, 2010
Removing ^M from end of the line in VI
:%s/^V^M//g
The ^v is a CONTROL-V character and ^m is a CONTROL-M. When you type this, it will look like this:
:%s/^M//g
In UNIX, you can escape a control character by preceding it with a CONTROL-V. The :%s is a basic search and replace command in vi. It tells vi to replace the regular expression between the first and second slashes (^M) with the text between the second and third slashes (nothing in this case). The g at the end directs vi to search and replace globally (all occurrences).
Friday, April 2, 2010
Invisible plugin in pidgin
wget http://fahhem.com/pidgin/gtalkinvisible.tar.gz
tar -vxf gtalkinvisible.tar.gz
mv gtalkinvisible/gtalkinvisible.so ~/.purple/plugins/
rm -rf gtalkinvisible*