Skip to content

Instantly share code, notes, and snippets.

@AjayAjaal
AjayAjaal / Naive.py
Last active December 12, 2015 02:34
Pattern Matching Algorithms
def naive(pattern, text):
occurrences = []
for i in range(len(text) - len(pattern) + 1):
match = True
for k in range(len(pattern)):
if text[i+k] != pattern[k]:
match = False
break
if match:
occurrences.append(i)
@AjayAjaal
AjayAjaal / index.php
Last active October 11, 2015 21:01
Simple URL Shortener in PHP
<?php
// load the links & Slugs from the file they're stored in
$links = parse_ini_file('links.ini');
// get the slug and remove any / characters
$slug = str_replace('/', '', $_SERVER['PATH_INFO']);
// check if the slug exists and if it corresponds to a link
if(isset($slug) && array_key_exists($slug, $links)){
<script type="text/javascript">
jQuery(document).ready(function(){
/*jQuery firing on add to cart button click*/
jQuery('.single_add_to_cart_button').click(function(){
/*Product meta data being sent; this is where you'd do your
document.getElementsByName or .getElementById*/
var product-meta-data = 'product-meta-data';
/*Ajax request URL being stored*/
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
jQuery.ajax({