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
// Based on https://stackoverflow.com/questions/565535/mocking-a-url-in-java | |
package com.example | |
import java.io.InputStream | |
import java.net.HttpURLConnection | |
import java.net.URL | |
class FakeResourceHttpURLConnection( | |
url: URL, |
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
/* | |
* Copyright (C) 2013 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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
# Your keymap | |
# | |
# Atom keymaps work similarly to style sheets. Just as style sheets use | |
# selectors to apply styles to elements, Atom keymaps use selectors to associate | |
# keystrokes with events in specific contexts. Unlike style sheets however, | |
# each selector can only be declared once. | |
# | |
# You can create a new keybinding in this file by typing "key" and then hitting | |
# tab. | |
# |
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
/** | |
* Copyright (c) 2013 Xcellent Creations, Inc. | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining | |
* a copy of this software and associated documentation files (the | |
* "Software"), to deal in the Software without restriction, including | |
* without limitation the rights to use, copy, modify, merge, publish, | |
* distribute, sublicense, and/or sell copies of the Software, and to | |
* permit persons to whom the Software is furnished to do so, subject to | |
* the following conditions: |
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
public static class ExceptionParser { | |
private final ResponseBody body; | |
private final String bodyString; | |
private final Converter.Factory converterFactory; | |
public ExceptionParser(Response response, Converter.Factory converterFactory) { | |
this.converterFactory = converterFactory; | |
this.body = cloneResponseBody(response.errorBody()); | |
this.bodyString = getBodyAsString(body); | |
} |
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
private fun <T> mutableLazy(initializer: () -> T) = Delegate(lazy(initializer)) | |
class Delegate<T>(private val lazy: Lazy<T>) { | |
private var value: T? = null | |
operator fun getValue(thisRef: Any?, property: KProperty<*>): T { | |
return value ?: lazy.getValue(thisRef, property) | |
} | |
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { |
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
// https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/ | |
use std::collections::HashMap; | |
use std::char; | |
use std::iter::FromIterator; | |
fn main() { | |
let mappings = init_map(); | |
find_combinations("23", mappings) | |
} |
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 length_of_longest_substring(str) | |
if str.empty? | |
return 0 | |
end | |
map = {} | |
curr_start = 0 | |
max_length = 0 | |
found_start = 0 | |
found_end = 0 | |
i = 0 |
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
inline fun <T> unless(stmt: () -> Boolean, block: () -> T, noinline elseBlock: (() -> T)? = null) = | |
if (!stmt.invoke()) { | |
block() | |
} else { | |
elseBlock?.invoke() | |
} | |
// Use like: | |
unless({ foo == bar }, { |
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
task('increaseVersionCode') << { | |
def manifestFile = file("src/main/AndroidManifest.xml") | |
def pattern = Pattern.compile("versionCode=\"(\\d+)\"") | |
def matcher = pattern.matcher((CharSequence)manifestFile.getText()) | |
matcher.find() | |
def versionCode = Integer.parseInt(matcher.group(1)) | |
manifestFile.write(matcher.replaceAll("versionCode=\"" + ++versionCode + "\"")) | |
} | |
assembleDebug.dependsOn 'increaseVersionCode' |