This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maximum' :: (Ord a) => [a] -> a | |
maximum' [] = error "maximum of empty list" | |
maximum' [x] = x | |
maximum' (x:xs) | |
| x > maxTail = x | |
| otherwise = maxTail | |
where maxTail = maximum' xs | |
-- using max | |
-- maximum' (x:xs) = max x (maximum' xs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* function $.fn.onVisible runs callback function once the specified element is visible. | |
* callback: A function to execute at the time when the element is visible. | |
* example: $(selector).onVisible(callback); | |
*/ | |
(function($) { | |
$.fn.onVisible = function (callback) { | |
var self = this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ko.bindingHandlers.filterDestroyed = | |
init: (element, valueAccessor, allBindings, viewModel, bindingContext) -> | |
filteredValueAccessor = -> | |
observableArray = valueAccessor() | |
_.filter observableArray(), (viewModel) -> | |
viewModel._destroy() is false | |
ko.bindingHandlers["template"]["init"] element, ko.bindingHandlers["foreach"].makeTemplateValueAccessor(filteredValueAccessor) | |
update: (element, valueAccessor, allBindings, viewModel, bindingContext) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Usage: | |
myView.setOnTouchListener(new OnSwipeTouchListener(this) { | |
@Override | |
public void onSwipeDown() { | |
Toast.makeText(MainActivity.this, "Down", Toast.LENGTH_SHORT).show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Usage: | |
myView.setOnTouchListener(new OnDoubleTapListener(this) { | |
@Override | |
public void onDoubleTap(MotionEvent e) { | |
Toast.makeText(MainActivity.this, "Double Tap", Toast.LENGTH_SHORT).show(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Recursively find all files in the directory with the extension ".js.cofee" and feeds the files into an input stream | |
# 2. Run `sed` to perform a string replace ('hello' => 'world') and create backup files | |
# 3. Find all the backup files and remove them recursively from the directory | |
find . -name "*.js.coffee" | while read a | |
do | |
sed -iBACKUP 's/hello/world/' $a | |
done | |
find . -name "*BACKUP" -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OPL.ViewModels.Lazy extends OPL.ViewModels.Base | |
### | |
lazyFlag is a string that holds the flag's name. | |
When the flag changes from false to true, it creates | |
the lazy objects and methods. When it changes from true | |
to false, it destroys the lazy objects and methods. | |
### | |
lazyFlag: "editMode" | |
constructor: -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# It returns a value called hw.cpu64bit_capable which is either 0 (not 64 bit compatible) or 1 (64 bit compatible) | |
sysctl hw | grep 64bit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Explanation of the various flags: | |
# --mirror – Makes (among other things) the download recursive. | |
# --convert-links – convert all the links (also to stuff like CSS stylesheets) to relative, so it will be suitable for offline viewing. | |
# --adjust-extension – Adds suitable extensions to filenames (html or css) depending on their content-type. | |
# --page-requisites – Download things like CSS style-sheets and images required to properly display the page offline. | |
# --no-parent – When recursing do not ascend to the parent directory. It useful for restricting the download to only a portion of the site. | |
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent http://example.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Grab pbpaste clipboard contents pipe them through js2coffe and paste it | |
" in the current buffer | |
function! PasteAsCoffee() | |
:read !pbpaste | js2coffee | |
endfunction | |
command! PasteAsCoffee :call PasteAsCoffee() |
OlderNewer