Skip to content

Instantly share code, notes, and snippets.

View kevgathuku's full-sized avatar

Kevin Gathuku kevgathuku

View GitHub Profile
@kevgathuku
kevgathuku / lyrics.py
Created October 14, 2014 07:52
Parse webpage for lyrics and save as a textfile in the current directory
import sys
import urllib2
from bs4 import BeautifulSoup
baseUrl = 'http://www.lyricsnmusic.com/'
def scrapLyrics(url):
#Takes the url as a parameter
artist = url.split('/')[3].split('-')
artist =' '.join(artist)
@kevgathuku
kevgathuku / query.sql
Last active August 29, 2015 14:08 — forked from hlashbrooke/query.sql
SELECT email_address, COUNT(email_address) AS occurrences
FROM users
GROUP BY email_address
HAVING occurrences > 1
@kevgathuku
kevgathuku / .bashrc
Last active August 29, 2015 14:10 — forked from clneagu/.bashrc
# Call virtualenvwrapper's "workon" if .venv exists. This is modified from--
# http://justinlilly.com/python/virtualenv_wrapper_helper.html
# which is linked from--
# http://virtualenvwrapper.readthedocs.org/en/latest/tips.html#automatically-run-workon-when-entering-a-directory
check_virtualenv() {
if [ -e .venv ]; then
env=`cat .venv`
if [ "$env" != "${VIRTUAL_ENV##*/}" ]; then
echo "Found .venv in directory. Calling: workon ${env}"
workon $env
@kevgathuku
kevgathuku / Dockerfile
Last active August 29, 2015 14:11
Basic Django Bootstraping Dockerfile
FROM ubuntu:14.04
RUN apt-get -qq update
RUN apt-get install -y python-dev python-setuptools python-software-properties
RUN easy_install pip
RUN pip install virtualenv
RUN virtualenv --no-site-packages /opt/env/djdocker
RUN /opt/env/djdocker/bin/pip install Django==1.6.8
RUN mkdir /opt/apps
RUN (cd /opt/apps && /opt/env/djdocker/bin/django-admin.py startproject djdocker)
RUN cd /opt/apps/djdocker
@kevgathuku
kevgathuku / main.rs
Created December 16, 2014 20:35
FizzBuzz implementation in Rust
fn main() {
for num in range(1i, 101i) {
if num % 15i == 0{
println!("FizzBuzz");
}
else if num % 3i == 0{
println!("Fizz")
}
else if num % 5i == 0{
println!("Buzz")
@kevgathuku
kevgathuku / even_odd.py
Last active August 29, 2015 14:11
A utility function to check if a number is even or odd through bitwise operation
from operator import and_
# An integer is odd only if its least significant bit is 1
def check_even(num):
if and_(num, 1) == 0:
print "{} is even".format(num)
else:
print "{} is odd".format(num)
if __name__ == '__main__':
@kevgathuku
kevgathuku / heroku_push_non_master.sh
Created January 13, 2015 13:41
Push non master branch to heroku
# This pushes the develop branch to heroku's master
git push heroku develop:master
@kevgathuku
kevgathuku / rerun.sh
Created January 14, 2015 21:04
Use the rerun program to build sphinx docs when a source file changes
# Run in verbose mode and ignore changes in the _build directory
rerun -v -i=_build "make html"
@kevgathuku
kevgathuku / rmline.py
Last active August 29, 2015 14:17
Delete a specified line from a file
#!/usr/bin/env python
import sys
filename = '/home/kevin/.ssh/known_hosts'
if len(sys.argv) != 2:
raise Exception(
"Please provide the line number to be deleted")
var numbers = [2, 3, 4, 66, 1]; //5
// Reverses an array in place
function reverse(A) {
var count = Math.floor(A.length / 2); // 2
for (var i = 0, last = A.length - 1; i < count; i++) {
var temp = A[i];
// Swap the array elements
A[i] = A[last - i];