Skip to content

Instantly share code, notes, and snippets.

View brianbirir's full-sized avatar
🎯
Focusing

Brian Birir brianbirir

🎯
Focusing
View GitHub Profile
@brianbirir
brianbirir / squash_rebase.sh
Last active September 4, 2023 10:15
Git Squash Rebase
#!/bin/sh
# Squash rebase all the commits in your working/feat. branch in one line against a base branch:
# git cherry -v base_branch | wc -l | awk '{print $1} gets the number of commits from the start of your branch
git rebase -i HEAD~$(git cherry -v base_branch | wc -l | awk '{print $1}')
@brianbirir
brianbirir / simple_multiplication.js
Last active February 23, 2023 18:15
Multiplying a given number by eight if it is an even number and by nine otherwise (Python, PHP and Javascript implementations)
function simpleMultiplication(number) {
return number * (number % 2 > 0 ? 9 : 8)
}
@brianbirir
brianbirir / find_needle.py
Created January 22, 2019 08:55
Find the needle word
def find_needle(haystack):
# initialize count
count = 0
# loop through haystack
for item in haystack:
count += 1
if item == 'needle':
return "found the needle at position {0}".format(count-1)
@brianbirir
brianbirir / reverse_words.py
Created January 15, 2019 08:20
Reverse words solution for Code Wars
def reverse_words(text):
words = text.split(' ')
new_sentence = []
for w in words:
# string to list i.e. array
new_word = list(w)
@brianbirir
brianbirir / pip_requirements.sh
Last active June 27, 2018 07:25
Upgrade outdated pip packages
#!/bin/sh
# run within root of project folder
pip freeze > requirements.txt
@brianbirir
brianbirir / parse.py
Created May 29, 2017 10:04
python - get filenames and folders of a directory using os walk
#!/usr/bin/python
import os
#globals
top = "/home/zuch/WWW/translate/archive" #root directory of archive
#node class
class node:
path = ""
@brianbirir
brianbirir / Cricket data.py
Created May 24, 2017 11:22 — forked from hybridjosto/Cricket data.py
scraping data from a web table using python and Beautiful Soup
import urllib2
from bs4 import BeautifulSoup
# http://segfault.in/2010/07/parsing-html-table-in-python-with-beautifulsoup/
f = open('cricket-data.txt','w')
linksFile = open("linksSource.txt")
lines = list(linksFile.readlines())
for i in lines[12:108]: #12:108
url = "http://www.gunnercricket.com/"+str(i)
try:
@brianbirir
brianbirir / encoding-video.md
Created December 1, 2016 08:12 — forked from Vestride/encoding-video.md
Encoding Video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aacc --with-opus