Skip to content

Instantly share code, notes, and snippets.

View kaveet's full-sized avatar
🏠
Working from home

Kaveet Laxmidas kaveet

🏠
Working from home
View GitHub Profile
@kaveet
kaveet / ocr-shot.sh
Created March 17, 2018 20:50 — forked from pnc/ocr-shot.sh
#!/bin/bash
set -e
CONTENTS=$(tesseract -c language_model_penalty_non_dict_word=0.8 --tessdata-dir /usr/local/share/ "$1" stdout -l eng | xml esc)
hex=$((cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@kaveet
kaveet / duplicate.hs
Created December 24, 2016 20:45
Haskell duplicate each entry in a list
module Duplicate where
duplicate :: [a] -> [a]
duplicate [] = []
duplicate (x:xs) = [x, x] ++ duplicate xs
@kaveet
kaveet / states-select.html
Created December 11, 2016 23:36
An HTML select element with options for the 50 US states and D.C.
<!-- A select element for the 50 US states and District of Columbia, with two letter state codes for values. -->
<select>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
@kaveet
kaveet / absoluteValue.hs
Created November 29, 2016 16:04
Haskell absolute value function for integers
module AbsoluteValue where
absoluteValue :: Int -> Int
absoluteValue n | n >= 0 = n
| otherwise = -n
@kaveet
kaveet / mySum.hs
Created November 26, 2016 18:47
Haskell sum implementation
module MySum where
sum :: [Int] -> Int
sum [] = 0
sum (x:xs) = x + sum xs
@kaveet
kaveet / myFilter.hs
Last active November 24, 2016 18:22
Haskell filter implementation with foldr
-- Problem 2: Write a function `filter'` that mimics the functionality of `filter` from the standard prelude, making use of `foldr`
module MyFilter where
filter' p = foldr (\x xs -> if p x then x : xs else xs) []
@kaveet
kaveet / myMap.hs
Last active November 23, 2016 02:12
Haskell Map Implementation with Foldr
-- Problem 1: Redefine Haskell's map using foldr from the standard prelude
module MyMap where
map' :: (a -> b) -> [a] -> [b]
map' f [] = []
map' f (x:xs) = foldr (\y ys -> (f y):ys) [] xs
@kaveet
kaveet / selectionSort.hs
Created November 21, 2016 15:03
Haskell Selection Sort
module SelectionSort where
selSort :: (Ord a) => [a] -> [a]
selSort [] = []
selSort xs = let x = maximum xs in selSort (remove x xs) ++ [x]
where remove _ [] = []
remove a (x:xs)
| x == a = xs
| otherwise = x : remove a xs
@kaveet
kaveet / insertionSort.hs
Created November 21, 2016 05:26
Haskell Insertion Sort
module InsertionSort where
import Data.List (insert)
insertsort :: Ord a => [a] -> [a]
insertsort = foldr insert []
@kaveet
kaveet / checkSort.hs
Last active December 9, 2022 07:31
Check if list is sorted in Haskell
module Sorted where
sorted :: (Ord a) => [a] -> Bool
sorted [] = True
sorted [x] = True
sorted (x:y:xs) = if x <= y then sorted (y:xs) else False