Skip to content

Instantly share code, notes, and snippets.

View hjoshi123's full-sized avatar
🎮
Fun with code

Hemant Joshi hjoshi123

🎮
Fun with code
View GitHub Profile
@hjoshi123
hjoshi123 / tempon.sh
Created March 6, 2021 05:15
Raspi's Temperature Monitor
#!/bin/bash
# This works only on raspbian
printf "%-15s%5s\n" "TIMESTAMP" "TEMP (deg C)"
printf "$20s\n" "-------------------------------"
while true
do
temp=$(vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*')
@hjoshi123
hjoshi123 / py_deps.sh
Created December 22, 2020 16:30
Setting up python dependencies using pyenv
source ~/.zshrc
pyenv --version
if [ $? -eq 0 ]; then
printf "\n${bold}Pyenv installed... moving ahead...\n"
ibrew install zlib
ibrew install readline
arch -x86_64 pyenv install $(pyenv install --list | grep -v - | grep -v b | tail -1)
arch -x86_64 pyenv global $(pyenv install --list | grep -v - | grep -v b | tail -1)
else
printf "\n${bold}Pyenv is not installed... Please try again...\n"
@hjoshi123
hjoshi123 / node_deps.sh
Created December 22, 2020 12:11
Node.JS installation
# Installing node
printf "\n${bold}Node.JS (Only v15 supported as of now)\n"
printf "Refer here for more details: https://github.com/nvm-sh/nvm/issues/2350\n"
. ~/.nvm/nvm.sh
nvm > /dev/null
if [ $? -eq 0 ]; then
printf "NVM Already installed... Proceeding further...\n"
node -v
if ! [ $? -eq 0 ]; then
nvm install node
@hjoshi123
hjoshi123 / deps_part1_brew_formulae.sh
Created December 18, 2020 10:16
Installing various brew formulae
# Array to install all the formulae some of them may require other taps so not including them here
commands_install=(
zsh-syntax-highlighting
go
android-platform-tools
htop
openjdk
redis
pyenv
)
@hjoshi123
hjoshi123 / deps_part1_brew.sh
Last active December 18, 2020 08:18
Setting up dev environment Part 1 which includes brew setup
# This just considers all existing aliases and path to the current script
source ~/.zshrc
# To make the text bold in shell
bold=$(tput bold)
# Function to check if a certain command/tool has been installed
check_install_result() {
if [ $? -eq 0 ]; then
printf "\n${bold}$1 installed successfully\n"
@hjoshi123
hjoshi123 / utils.go
Created December 8, 2020 05:04
Sending Message to Telegram
// SendTextToTelegram sends text to the user
func SendTextToTelegram(chatID int, text string, keyboard []byte) (string, error) {
log.Printf("Sending to chat_id: %d", chatID)
// log.Printf(string(keyboard))
log.Printf(text)
response, err := http.PostForm(
types.TelegramAPI,
url.Values{
"chat_id": {strconv.Itoa(chatID)},
@hjoshi123
hjoshi123 / utils.go
Created December 7, 2020 12:31
Parse Telegram Update
// ParseTelegramUpdate takes in the request from telegram and parses Update from it
func ParseTelegramUpdate(r *http.Request) (*types.Update, error) {
var update types.Update
if err := json.NewDecoder(r.Body).Decode(&update); err != nil {
return nil, err
}
return &update, nil
}
@hjoshi123
hjoshi123 / tele_types.go
Last active December 8, 2020 04:26
Update Telegram struct
// Update is the type of request that telegram sends once u send message to the bot
type Update struct {
UpdateID int `json:"update_id"`
Message Message `json:"message"`
CallbackQuery CallbackQuery `json:"callback_query"`
}
// Message is the structure of the message sent to the bot
type Message struct {
Text string `json:"text"`
@hjoshi123
hjoshi123 / break.go
Created August 3, 2020 14:03 — forked from jnovack/break.go
Handle CTRL-C in Golang
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
Verifying my Blockstack ID is secured with the address 13oMTebk6yMJKKiJLsvqjTUXKTXyycHpQh https://explorer.blockstack.org/address/13oMTebk6yMJKKiJLsvqjTUXKTXyycHpQh