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
/** | |
* Set the title of this toolbar. | |
* | |
* <p>A title should be used as the anchor for a section of content. It should | |
* describe or name the content being viewed.</p> | |
* | |
* @param title Title to set | |
*/ | |
public void setTitle(CharSequence title) { | |
if (!TextUtils.isEmpty(title)) { |
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
on readPassword() | |
try | |
-- (1) | |
set logFile to (path to documents folder) as text | |
set theFolder to POSIX path of logFile | |
set passwordFile to theFolder & "password.txt" | |
-- (2) | |
open for access passwordFile |
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
on writePassword(title, passwordString) | |
try | |
-- (1) | |
set textToBeWritten to "\n" & title & ":" & passwordString | |
-- (2) | |
set documentsPath to path to documents folder as text | |
set passwordFile to documentsPath & "password.txt" | |
set the logFile to ((path to documents folder) as text) & "password.txt" |
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
on generatePassword() | |
set chars to {} | |
set shuffledChars to {} | |
-- (1) | |
repeat with index from 1 to 15 | |
if index is less than 5 then | |
set chars to chars & some item of lowercase | |
else if index is less than 10 then | |
set chars to chars & some item of uppercase |
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 checkVisibleItem(element) { | |
//1 | |
let base = $('.slider-item').add(element); | |
base.filter((index, element) => { | |
//2 | |
return $(element).attr('class').match(/slider-item-\d+/); | |
}).each((index, element) => { | |
//3 | |
}); |
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
/* | |
ptrack-content div contains an attribute 'data-ui-tracking-context' | |
which contains the information regarding video_id of the element. | |
It's a url-encoded JSON string. | |
*/ | |
function getVideoId(element) { | |
let ptrack_content = $(element).find('.ptrack-content'); | |
if(ptrack_content && ptrack_content.length > 0) { | |
let tracking_data = ptrack_content.attr('data-ui-tracking-context'); | |
let decoded_tracking_data = decodeURIComponent(tracking_data); |
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 --> | |
<div class="slider-item slider-item-0"> | |
<div ..> | |
<div ..> | |
<!-- 2 --> | |
<div class="ptrack-content" | |
data-ui-tracking-context="..."> | |
<a ..> | |
<div ..> | |
<img class="boxart-image boxart-image-in-padded-container" ..> |
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
// All return a type Monad | |
val split: (String) -> Monad<Pair<StringPair, StringPair>> = { str -> | |
.. | |
Monad.Something(Pair(..)) | |
} | |
val convertToInt: (pair: Pair<StringPair, StringPair>) -> Monad<Pair<IntPair, IntPair>> = { pair -> | |
.. | |
Monad.Something(Pair(..)) |
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
typealias StringPair = Pair<String, String> | |
typealias IntPair = Pair<Int, Int> | |
//this is prone to exception if str isn't in the right format e.g., "1, 2, 3, 4, 5" | |
val split: (String) -> Pair<StringPair, StringPair> = { str -> | |
val (a, b, c, d) = str.split(",") | |
Pair(Pair(a, b), Pair(c, d)) | |
} | |
val convertToInt: (pair: Pair<StringPair, StringPair>) -> Pair<IntPair, IntPair> = { pair -> |
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
sealed class Monad<out T> { | |
object Nothing: Monad<kotlin.Nothing>() | |
data class Something<out T>(val value: T): Monad<T>() | |
inline fun<S> flatMap(f: (T) -> Monad<S>): Monad<S> = when(this) { | |
is Nothing -> this | |
is Something -> f(this.value) // we aren't wrapping f(value) again | |
// since it already returns a wrapped value |