Skip to content

Instantly share code, notes, and snippets.

View Pk13055's full-sized avatar
🇦🇪
Focusing

Pk13055

🇦🇪
Focusing
View GitHub Profile
@Pk13055
Pk13055 / grades.py
Created June 17, 2017 13:23
Small script to calculate cgpa
#!/usr/bin/python3
# enter details as follows credit mark credit mark ..
# ex: ./grades.py 5 A- 3 A 4 B- ...
from sys import argv as rd
grades = { 'A' : 10, 'A-' : 9, 'B' : 8, 'B-' : 7, 'C' : 6, 'C-' : 5 , 'D' : 4, 'F' : 2}
courses = list(map(lambda x: [float(x[0]), grades[x[-1]]], [[x, y] for x, y in zip(rd[1:], rd[1:][1:])][::2]))
print(sum([x[0] * x[-1] for x in courses]) / sum([x[0] for x in courses]))
@Pk13055
Pk13055 / list_recur.py
Created June 17, 2017 13:27
List manipulator scripts
# this function recursively performs an operation on nested lists element-wise
import operator
def list_recur(l1, l2, op = operator.add):
if not l1:
return type(l1)([])
elif isinstance(l1[0], type(l1)):
return type(l1)([list_recur(l1[0], l2[0], op)]) + list_recur(l1[1:],l2[1:], op)
else:
return type(l1)([op(l1[0], l2[0])]) + list_recur(l1[1:], l2[1:], op)
# flatten deep nested lists
def flatten(S):
if S == []:
return S
if isinstance(S[0], list):
return flatten(S[0]) + flatten(S[1:])
return S[:1] + flatten(S[1:])
@Pk13055
Pk13055 / app.py
Created July 3, 2017 23:05
Python Flask App (simple SPA, no modules)
from flask import Flask, request, redirect, url_for, render_template
import sys, os
# this creates our Flask app
app = Flask(__name__)
# define all your routes here
@app.route('/', methods = ['POST', 'GET'])
@Pk13055
Pk13055 / git-tree.sh
Last active July 13, 2017 01:01
Bash Script to make a git tree with links
#!/bin/bash
tree=$(tree -tf --noreport -I '*~' --charset ascii $1 |
sed -e 's/| \+/ /g' -e 's/[|`]-\+/ */g' -e 's:\(* \)\(\(.*/\)\([^/]\+\)\):\1[\4](\2):g')
printf "# Project tree\n\n${tree}"
@Pk13055
Pk13055 / github-print-bookmarklet
Created August 3, 2017 17:24 — forked from BenjaminKlatt/github-print-bookmarklet
Bookmarklet for Removing GitHub Frame for Printing
javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f=e.jQuery)%7C%7Cg%3Ef.fn.jquery%7C%7Ch(f))%7Bc=a.createElement(%22script%22);c.type=%22text/javascript%22;c.src=%22http://ajax.googleapis.com/ajax/libs/jquery/%22+g+%22/jquery.min.js%22;c.onload=c.onreadystatechange=function()%7Bif(!b&&(!(d=this.readyState)%7C%7Cd==%22loaded%22%7C%7Cd==%22complete%22))%7Bh((f=e.jQuery).noConflict(1),b=1);f(c).remove()%7D%7D;a.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,%221.3.2%22,function($,L)%7B$('%23header,%20.pagehead,%20.breadcrumb,%20.commit,%20.meta,%20%23footer,%20%23footer-push,%20.wiki-actions,%20%23last-edit,%20.actions,%20.header,.site-footer,.repository-sidebar,.file-navigation,.gh-header-meta,.gh-header-actions,#wiki-rightbar,#wiki-footer').remove();%20$('%23files,%20.file').css(%7B%22background%22:%22none%22,%20%22border%22:%22none%22%7D);%20$('link').removeAttr('media');%7D);
@Pk13055
Pk13055 / how-to-squash-commits-in-git.md
Created October 5, 2017 03:36 — forked from patik/how-to-squash-commits-in-git.md
How to squash commits in git

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

@Pk13055
Pk13055 / zsh_history_fix.sh
Created October 6, 2017 06:15
Fix zsh history corrupt
#!/bin/bash
cd ~;
mv .zsh_history .zsh_history_bad;
strings .zsh_history_bad > .zsh_history;
fc -R .zsh_history;
@Pk13055
Pk13055 / multi-cp.sh
Created October 23, 2017 10:39
Copy multiple files or directories to multiple locations
#!/bin/bash
k=0
l=0
flag=1
files=()
locs=()
for i in $@
do
if [ "$i" = "," ]
then
@Pk13055
Pk13055 / tmux-cheatsheet.markdown
Created October 30, 2017 19:20 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname