Skip to content

Instantly share code, notes, and snippets.

// Originally posted on: https://rubdotto.com/clean-code-desinformaci%C3%B3n/
findDragonBall()
findDragonBalls()
findDragonBells()
findDragonWithBalls()
findDragonWithBalletSlippers()
@rubdottocom
rubdottocom / bad_variable_names_1.java
Last active April 28, 2019 06:26
Clean code examples
// Originally posted on: https://rubdotto.com/clean-code-nombre-de-variables/
public boolean isSS(int r, int hc, int e) {
if (r != 3) {
return false;
}
if (hc != 0xFFFFFF00) {
return false;
}
if (e < 1000000) {
return false;
@rubdottocom
rubdottocom / find_items_in_dict_by_key.py
Created February 22, 2019 15:43
Find all occurrences of a key in nested python dictionaries
def gen_dict_extract(node, kv):
if isinstance(node, list):
for i in node:
for x in gen_dict_extract(i, kv):
yield x
elif isinstance(node, dict):
if kv in node:
yield node[kv]
for j in node.values():
for x in gen_dict_extract(j, kv):
@rubdottocom
rubdottocom / HowToUseIt.kt
Created June 13, 2018 13:49
Extension functions to work more comfortably with JSONObject. The idea is to capture nulls instead of Exception or bother with .has function
// WARNING, this code doesn't work, is an example of usage
val json = JSONObject()
json.safeGetString("property")?.let {
// Do awesome things with property value
}
@rubdottocom
rubdottocom / AwesomeTimberLog.kt
Created February 21, 2018 12:10
Logs with links to source code using Awesome Console IntelliJ plugin
// Works with Awesome Console IntelliJ plugin
// https://plugins.jetbrains.com/plugin/7677-awesome-console
import timber.log.Timber // https://github.com/JakeWharton/timber
class AwesomeTimberLog {
fun doLogWithLinkToSourceCode() {
Timber.d("Hello World! - " + UtilsK.getLinkToSourceFile(Thread.currentThread().stackTrace[2]))
}
}
@rubdottocom
rubdottocom / transparent_text_on_image.php
Last active December 31, 2015 19:59
PHP - Add transparent text watermark to an image to make it binary unique
<?php
// Create image resuource, use 'imagecreate*' that you need
$im = imagecreatefromstring($img_string);
imagesavealpha($im, true);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127); // transparent background
imagefill($im, 0, 0, $trans_colour);
$text_color = imagecolorallocatealpha($im, 0, 0, 0, 126); // almost transparent text color "not visible human eye"
imagestring($im, 1, 0, 0, "UNIQUE_ID", $text_color);
@rubdottocom
rubdottocom / gist:2836555
Created May 30, 2012 14:08
Shell: Execute go-pear.phar on Debian Squeeze
php -d suhosin.executor.include.whitelist="phar" go-pear.phar
@rubdottocom
rubdottocom / gist:2720834
Created May 17, 2012 18:43
Objective-C: Clean Cache and Cookie from UIWebView
//Set Cache
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
//Clear All Cookies
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
@rubdottocom
rubdottocom / gist:2633679
Created May 8, 2012 08:53
PHP: Complex object var_dump
public function str_var_dump($object)
{
ob_start();
var_dump($object);
$dump = ob_get_clean();
return $dump;
}
@rubdottocom
rubdottocom / gist:2633658
Created May 8, 2012 08:49
CodeIgniter: Log database error function
public function log_database_error($last_query, $error_message, $error_number, $data = null)
{
log_message('debug', __METHOD__);
if ($data) {
log_message('error', "data: " . $this->str_var_dump($data));
}
log_message('error', "query: " .$last_query);
log_message('error', "DB Error: ".$error_message." (ERR_NUM: ".$error_number.")");
}