Skip to content

Instantly share code, notes, and snippets.

Avatar

Ashaba John Ashaba

View GitHub Profile
@Ashaba
Ashaba / merge_arrays.py
Created Jul 5, 2019
A function that merges two arrays together at a given length creating one array array
View merge_arrays.py
def merge_arrays(a, b, c):
index = 0
b_index = 0
b_len = len(b)
d = []
for i in a:
d.append(i)
index += 1
if index == c:
View animalChallengev2.java
package challenge;
import java.util.HashMap;
/**
* You have 10,000/= bob, and you need to buy exactly 100 animals:
* - cows @1000/-
* - pigs @200/-
* - chicken @50/-
View animalChallengev1.java
package challenge;
/**
* You have 10,000/= bob, and you need to buy exactly 100 animals:
* - cows @1000/-
* - pigs @200/-
* - chicken @50/-
*
* 1. You must have at least one of each animal
* 2. You must use up all Ksh. 10K
View Depth-first_search.py
"""
There are N countries {1,2,3,4....N} and N-1 roads(i.e depicting a tree)
Bishu lives in the Country 1 so this can be considered as the root of the tree.
Now there are Q girls who live in various countries (not equal to 1) .
All of them want to propose Bishu. But Bishu has some condition.
He will accept the proposal of the girl who lives at minimum distance from his country.
View Depth-first_search
View Breadth-first_search
View scripts.sh
#!/usr/bin/env bash
mkdir directory1 directory2 directory3 #create multiple directories
pwd #show the current directory
ls # list contents of a directory
cd directory1 # move to a particular directory
touch script.py # create a file
cp script.py ../directory2 # copy contents a file to another directory
echo "foo" | xargs touch #command with pipes
View commit-msg.rb
#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
$regex = /\((\w+)\):/
if !$regex.match(message)
puts "[POLICY] Your message is not formatted correctly"
puts "[STANDARD] Your message should be in the format: ‘feat(module): commit message’ "
exit 1
end
View pre-rebase.sh
$ mv pre-rebase.sample pre-rebase #renaming sample to pre-rebase.
#!/bin/sh
publish=next
basebranch="$1"
if test "$#" = 2
then
topic="refs/heads/$2"
else
topic=`git symbolic-ref HEAD` ||
exit 0 ;# we do not interrupt rebasing detached HEAD
View pre-commit-custom.sh
alias pythonfiles='find . -type f -name "*.py" | xargs git diff --cached --name-only $against'
if [ -n "$(pythonfiles)" ]; then
if pythonfiles | xargs grep --color --with-filename -n "import pdb"; then
echo "Error commiting changes: Please remove pdb and its usage"
exit 1
fi
if pythonfiles | xargs grep --color --with-filename -n "pdb.set_trace()"; then
echo "Error commiting changes: Please remove pdb and its usage"
exit 1
fi
You can’t perform that action at this time.