Skip to content

Instantly share code, notes, and snippets.

@ameerkat
ameerkat / BoyerMooreStringSearch.py
Created October 14, 2010 17:46
Boyer Moore string search implementation in Python
# Boyer Moore String Search implementation in Python
# Ameer Ayoub <ameer.ayoub@gmail.com>
# Generate the Bad Character Skip List
def generateBadCharShift(term):
skipList = {}
for i in range(0, len(term)-1):
skipList[term[i]] = len(term)-i-1
return skipList
@JamieMason
JamieMason / is_installed.sh
Last active February 17, 2024 10:12
Check if a program exists from a bash script.Thanks to twitter.com/joshnesbitt and twitter.com/mheap for the help with detecting npm packages.
#!/bin/bash
# Functions ==============================================
# return 1 if global command line program installed, else 0
# example
# echo "node: $(program_is_installed node)"
function program_is_installed {
# set to 1 initially
local return_=1
@gagangowda
gagangowda / Json_Concatenation.py
Last active December 28, 2015 19:59
Combining Two Json Objects in Python
import json
def combine_json():
with open('j1.json') as file:
d1 = json.loads(file.read())
with open('j2.json') as file:
d2 = json.loads(file.read())
result = combine_dict(d1,d2)
j3 = json.dumps(result)
return j3