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
try: | |
# Do something | |
except Exception as e: | |
import traceback | |
import sys | |
exc_info = sys.exc_info() | |
traceback.print_exception(*exc_info) | |
del exc_info | |
# Handle Exception | |
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
""" | |
Sample Output | |
[0] | |
[1] [2] | |
[3] [4] [5] [6] | |
[7] [8] [9] [ ] [ ] [ ] [ ] [ ] | |
""" |
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
fun List<Int>.isEqualTo(other: List<Int>): Boolean { | |
if (this.size != other.size) { | |
return false | |
} | |
return (0..this.size - 1).all { this[it].equals(other[it]) } | |
} | |
fun List<Int>.isNotEqualTo(other: List<Int>): Boolean { | |
if (this.size != other.size) { | |
return true |
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
data class Lock<T: Any>(private val obj: T) { | |
public fun acquire(func: (T) -> Unit) = synchronized (obj) { | |
func(obj) | |
} | |
} |
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
exists = function(obj) { | |
if (typeof obj !== 'undefined') { | |
if (obj !== null && obj !== undefined) { | |
if (typeof obj === 'string') { | |
return obj !== ''; | |
} else if (typeof obj === 'number') { | |
return obj !== 0; | |
} else { | |
/* Node.js supports JSON.stringify(obj) syntax. | |
* For other versions of JS, this should be replaced with appropriate syntax. |
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
var mysql = require("mysql"); | |
// Configure your logger here | |
var logger = require("../utils/logger"); | |
// Add a properties file here with the configurations | |
// For properties file format visit https://github.com/steveukx/properties | |
var properties = require('properties-reader')('properties.properties'); | |
function getConnection() { | |
var connection = mysql.createConnection({ | |
host: properties.get('mysql.host'), |
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
'.source.python': | |
'Snippet Name': | |
'prefix': 'setup' | |
'body': """ | |
def answer(): | |
pass | |
def main(): | |
for case in range(int(raw_input())): |
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
extension UIColor { | |
convenience init(red: Int, green: Int, blue: Int) { | |
assert(red >= 0 && red <= 255, "Invalid red value") | |
assert(green >= 0 && green <= 255, "Invalid green value") | |
assert(blue >= 0 && blue <= 255, "Invalid blue value") | |
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0) | |
} | |
convenience init(rgb: Int) { |
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 console_confirmation(question, retries=4, message='Bad answer! Please try again.'): | |
""" | |
Prompts user on the standard console for confirmation. | |
The user can choose one of multiple meanings either meaning Yes or No. | |
Any other input will result in a bad input and the user will be prompted again. | |
The user will be allowed to enter bad inputs exactly equal to the value of 'retries' parameter. | |
Valid inputs for Yes response are 'y', 'yes', 'sure', 'alright', 'right', 'all right', 'positive', 'certainly', 'for sure', 'indeed', 'agreed', 'absolutely', 'affirmative' | |
Valid inputs for No response are 'n', 'no', 'nope', 'na', 'nah', 'nada', 'negative', 'not really', 'not', 'no way', 'no ways' | |
""" | |
answer = raw_input(question + '\n') |