Skip to content

Instantly share code, notes, and snippets.

View zarinfam's full-sized avatar

Saeed Zarinfam zarinfam

View GitHub Profile
@zarinfam
zarinfam / gist.java
Created July 29, 2019 07:57
Created with Copy to Gist
public void handlePrinting(String text) {
try {
printText(text);
} catch (PrintingException e) {
// handle the exception and decide what to do
// retry or show an error message and ...
return;
}
// successful printing and ...
}
@zarinfam
zarinfam / gist.java
Last active July 29, 2019 07:40
Created with Copy to Gist
public synchronized void printText(String text) throws PrintingException {
PrintingListener printingListener = new PrintingListener() {
@Override
public void onSuccess(SuccessResult successResult) {
}
@Override
public void onFailure(FailureResult failureResult) {
}
@zarinfam
zarinfam / gist.java
Created July 29, 2019 07:21
Created with Copy to Gist
public synchronized void printText(String text) throws PrintingException {
// communication with printer using API here
}
@zarinfam
zarinfam / gist.hs
Created July 25, 2019 09:17
Created with Copy to Gist
getIntOr0 :: Maybe Int -> Int
getIntOr0 = fromMaybe 0
@zarinfam
zarinfam / gist.hs
Created July 25, 2019 09:13
Created with Copy to Gist
fromMaybe :: a -> Maybe a -> a
import Data.List
import Data.Ord
main :: IO ()
main = print $ desort [2,8,7,10,1,9,5,3,4,6]
desort :: [Integer] -> [Integer]
desort = reverse . sort -- better use: sortOn Data.Ord.Down
isPow2Even :: Integer -> Bool
isPow2Even = even . pow2 --instead of: even $ pow2 a
isPow2Even :: Integer -> Bool
isPow2Even a = even $ pow2 a --or even (pow2 a)
main :: IO ()
main = print (pow2 3) -- or print $ pow2 3
pow2 :: Integer -> Integer
pow2 a = a * a