Skip to content

Instantly share code, notes, and snippets.

View surajsau's full-sized avatar
🙇‍♂️
よろしくお願いします!

Suraj Kumar Sau surajsau

🙇‍♂️
よろしくお願いします!
View GitHub Profile
@surajsau
surajsau / Toolbar#setTitle.java
Last active August 6, 2020 16:39
AOSP implementation of Toolbar.setTitle()
/**
* 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)) {
@surajsau
surajsau / read_password.scpt
Created May 24, 2020 10:22
Applescript for password retrieval from file
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
@surajsau
surajsau / store_password.scpt
Created May 24, 2020 10:20
Applescript for storing the password mapping
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"
@surajsau
surajsau / generate_password.scpt
Created May 24, 2020 10:17
Applescript for Password Generation
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
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
});
/*
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);
<!-- 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" ..>
// 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(..))
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 ->
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