Skip to content

Instantly share code, notes, and snippets.

@atifazad
atifazad / Setup Virtualenvwrapper
Last active March 4, 2020 23:27
Setup virtualenvwrapper on Mac OS Catalina
# Step-1: Install Homebrew, if you don’t have it already.
# There are other possibilities as well to install Python3 but I recommend installing it via Homebrew for cleaner installation and easier maintenance (upgrade etc).
# > /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# Step-2: Install Python3 (pip3 gets installed automatically)
# > brew install python3
# Step-3: Install Virtualenvwrapper
# > sudo -H pip3 install virtualenvwrapper
@atifazad
atifazad / Dockerfile
Last active February 21, 2020 21:40
Create your first Docker image based on alpine image
# Start with Linux Alpine image as base
FROM alpine:latest
# Install curl
apk add --no-cache curl
@atifazad
atifazad / Python Basics
Last active February 16, 2020 17:18
Python programming basics
Python basics step by step examples
@atifazad
atifazad / Hello World!
Last active February 15, 2020 18:26
Hello World! in various languages and frameworks (embedded in https://atifazad.com/tutorials/general/hello-world/)
This gist contains Hello World examples for several programming languages and framworks. This codes from this gist are being used (as embed code) at Hello World page at my weebsite (https://atifazad.com/tutorials/general/hello-world/)
#import <Foundation/Foundation.h>
@interface Solution : NSObject
- (NSString *)countAndCall: (int) n;
- (NSString *)count:(int) n;
@end
@implementation Solution
- (NSString *)countAndCall: (int) n {
@atifazad
atifazad / mac_shutdown.py
Created July 27, 2017 12:19
Python script to shutdown mac
# -*- coding: utf-8 -*-
import subprocess
subprocess.call(['osascript', '-e', 'tell app "loginwindow" to «event aevtrsdn»'])
#usage: > python mac_shutdown.py
# For further similar system commands: https://gist.github.com/atifazad/6afd3cbedb8819dd7ed7be92dec2dc0d
@atifazad
atifazad / sysquit_commands.md
Last active April 24, 2024 01:01
osascript commands to shutdown, restart, sleep and logout mac

Shut down without showing a confirmation dialog:

osascript -e 'tell app "System Events" to shut down'

Shut down after showing a confirmation dialog:

osascript -e 'tell app "loginwindow" to «event aevtrsdn»'
@atifazad
atifazad / quit.py
Created July 27, 2017 11:19
Python script to close mac apps
import subprocess
import sys
if len(sys.argv) == 1 :
print "missing program name to quit"
else:
program=sys.argv[1]
quitCommand='tell application "' + program + '" to quit'
print "quiting " + program
subprocess.call(['osascript', '-e', quitCommand])
@atifazad
atifazad / gist:b1986422f9696d2784708b93931e4053
Created May 3, 2016 10:34
Rename a Git branch local and remote
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@atifazad
atifazad / gist:61abb37fb2328c60b1d4b658e66deb3a
Created May 3, 2016 10:31
Hash of last commit of a Git branch
Get hash of last commit (eg. 1fa01e4b90a09069a5aa6482a71c5f76118eef9e)
git rev-parse HEAD
Get short hash of last commit (eg. 1fa01e4)
git rev-parse --short HEAD