Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Hello stranger looking at my work!

Mohan Sha MohanSha

👨‍💻
Hello stranger looking at my work!
View GitHub Profile
@MohanSha
MohanSha / main.go
Created Feb 12, 2021 — forked from qeubar/main.go
Parse top-level json array in Go
View main.go
/*
Some json APIs tend to present list responses in
a single array not wrapped in the usual { "results" :[] } style.
Below is a simple way of parsing [ { ... }, { ... }, ... ] json responses.
*/
package main
import (
@MohanSha
MohanSha / clean_code.md
Created Mar 20, 2020 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin
View clean_code.md

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@MohanSha
MohanSha / slack_history.py
Created Sep 18, 2018 — forked from minniel/slack_history.py
Download Slack Channel/PrivateChannel/DirectMessage History
View slack_history.py
from slacker import Slacker
import json
import argparse
import os
import shutil
import copy
from datetime import datetime
# This script finds all channels, private channels and direct messages
# that your user participates in, downloads the complete history for
View gist:ede9efa864b988abe3a802d8430802ae
<?
/////////////////////
// slack2html
// by @levelsio
/////////////////////
//
/////////////////////
// WHAT DOES THIS DO?
/////////////////////
//
@MohanSha
MohanSha / cloudMail.py
Last active Jul 2, 2018
Send email from a cloud server
View cloudMail.py
SERVER = "outlook.office365.com"
FROM = "mohan.sha@qubecinema.com"
TO = ["mohan.sha@qubecinema.com"] # must be a list
SUBJECT = "Cloud Test mail"
TEXT = "This mail was sent from mohan.sha@qubecinema.com email"
# Prepare actual message
message = """From: %s\r\nTo: %s\r\nSubject: %s\r\n\
View RandomFileGenerator.py
#!/usr/bin/env python
## TODO: less mixed file types DONE
## TODO: less ramifications (truncate after a certain depth) DONE
## TODO: file/dir modification and removal DONE
from __future__ import print_function
import os, random, string, subprocess, time, shutil, md5
extensions = ['css', 'js', 'html', 'cpp', 'txt', 'png', 'c']
def make_empty_file(path, name):
View GuessTheNumber.py
# template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
"""import some modules"""
import random, simplegui
# initialize global variables used in your code
secret_number = random.randrange(0, 100)
secret_number_range = 100
View GuessTheNumber.py
# template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
"""import some modules"""
import random, simplegui
# initialize global variables used in your code
secret_number = random.randrange(0, 100)
secret_number_range = 100
@MohanSha
MohanSha / RockPaperScissorsLizardSpock.py
Created Feb 13, 2018
Based on The Big Bang Theory Sheldon's game
View RockPaperScissorsLizardSpock.py
# Rock-paper-scissors-lizard-Spock template
# The key idea of this program is to equate the strings
# "rock", "paper", "scissors", "lizard", "Spock" to numbers
# as follows:
#
# 0 - rock
# 1 - Spock
# 2 - paper
@MohanSha
MohanSha / Snake.py
Created Feb 13, 2018
Classic Snake Game
View Snake.py
import pygame
import random
import sys
from pygame.locals import *
def collide(x1,x2,y1,y2,wh):
w1=20;
w2=wh;
h2=wh;
h1=20;
if x1+w1>x2 and x1<x2+w2 and y1+h1>y2 and y1<y2+h2: