A series of exercises to get a feel for how generic types and type variables work in Elm.
For each of these, you are given some code that is not compiling. Your task is to get it
compiling. You can change the body of the function but not the signature. No cheating
with Debug.todo
or infinite recursions either 😉
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
// Stock Android Browser Check >>>>>>>>>>>>>>>> | |
var ua = navigator.userAgent.toLowerCase(); | |
var isAndroid = ua.indexOf("android") > -1 && ua.indexOf("mobile") && ua.indexOf("chrome")==-1 | |
if(isAndroid) { | |
// stuff | |
} |
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
img:hover { | |
-webkit-filter: grayscale(0%); | |
-webkit-transition: .5s ease-in-out; | |
-moz-filter: grayscale(0%); | |
-moz-transition: .5s ease-in-out; | |
-o-filter: grayscale(0%); | |
-o-transition: .5s ease-in-out; | |
} | |
img { |
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
// Let's make it possible to create pure functions even when we're | |
// dealing with impure operations that would have side effects! | |
// First we'll need a "Type" that can contain a (sometimes impure) function | |
function IO(fn) { | |
if (!(this instanceof IO)) {//make it simpler for end users to create a type without "new" | |
return new IO(fn); | |
} | |
this.runIO = fn;//IO now provides an extra control layer that allows the composition of unexecuted effects |
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
/** | |
* Polyfill for Object.keys | |
* | |
* @see: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys | |
*/ | |
if (!Object.keys) { | |
Object.keys = (function () { | |
var hasOwnProperty = Object.prototype.hasOwnProperty, | |
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), | |
dontEnums = [ |
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
babel github-es6.js -o github.js --optional runtime --experimental |
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
/* | |
If you try to print a gitbook directly, you get nothing but the contents because of their *just* use of `@media print` styling to hide away the content section of the books. | |
Fret not, here is the codez: | |
*/ | |
$(".book-header,.book-summary,.navigation,.book-progress").remove(); | |
$(".book.with-summary .book-body").css('left', '0px'); | |
$("*").css('position', 'static'); | |
window.print() |
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
def f(diff, n): | |
""" | |
This function returns the new difficulty. | |
""" | |
period_count = (n + 1) // 100000 | |
return max(diff + 2**(period_count - 1), 5000) | |
| |
diff = 6232935860523 # starting diffculty | |
blocknumber = 200000 # starting blocknumber | |
numberOfBlocks2years = 2*365*24*60*60/15 |
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
#!/usr/bin/env bash | |
# checks if branch has something pending | |
function parse_git_dirty() { | |
git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "*" | |
} | |
# gets the current git branch | |
function parse_git_branch() { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" |
OlderNewer