- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
Object o1 = true ? Integer.valueOf(1) : Double.valueOf(2.0);
Object o2;
if (true) {
o2 = Integer.valueOf(1);
} else {
o2 = Double.valueOf(2.0);
}
System.out.println(o1);
System.out.println(o2);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+79
Object o1 = true ? Integer.valueOf(1) : Double.valueOf(2.0);
Object o2;
if (true) {
o2 = Integer.valueOf(1);
} else {
o2 = Double.valueOf(2.0);
}
System.out.println(o1);
System.out.println(o2);
Такие вот в Java интересные типы-обёртки.
Проверить себя: http://ideone.com/BrhREq
Источник: http://java.dzone.com/articles/10-things-you-didnt-know-about
+137
//Перевести строку в JSON
#region ConvertToJson
public static string ConvertToJson(string str)
{
return str.Replace(@"/", string.Empty).Replace(@"~", string.Empty).Replace(@":", string.Empty).Replace(@"{", string.Empty).Replace(@"}", string.Empty).Replace("\"", string.Empty).Replace(",", string.Empty).Replace("\n", string.Empty);
}
#endregion
json сериализатор из строки в строку, написанный в одну строчку
+53
const char *GetExternalFilesDir ()
{
assert (started);
static std::string s="";
if (s.length()==0)
{
LOGI("Try get external files dir");
jclass c; jmethodID m; jobject o;
c = env->FindClass ("android/app/NativeActivity");
m = env->GetMethodID (c, "getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;");
o = env->CallObjectMethod (appState->activity->clazz, m, NULL);
c = env->GetObjectClass (o);
m = env->GetMethodID (c, "getAbsolutePath", "()Ljava/lang/String;");
o = env->CallObjectMethod (o, m);
jstring jo = (jstring)o;
const char *path = env->GetStringUTFChars(jo, NULL);
s=path;
env->ReleaseStringUTFChars(jo, path);
s+='/';
LOGI("Path for program's data files is %s", s.c_str());
}
return s.c_str();
}
Этот код был написан одним очень известным в очень узких кругах человеком. Будем надеяться, что он придет в обсуждение и прокомментирует его.
+126
If v1 = 1 Then
t1 = " "
ElseIf v1 = 2 Then
t1 = "q"
ElseIf v1 = 3 Then
t1 = "w"
ElseIf v1 = 4 Then
t1 = "e"
ElseIf v1 = 5 Then
t1 = "r"
ElseIf v1 = 6 Then
t1 = "t"
ElseIf v1 = 7 Then
t1 = "y"
ElseIf v1 = 8 Then
t1 = "u"
ElseIf v1 = 8 Then
t1 = "u"
ElseIf v1 = 9 Then
t1 = "i"
ElseIf v1 = 10 Then
t1 = "o"
ElseIf v1 = 11 Then
t1 = "p"
ElseIf v1 = 12 Then
t1 = "a"
ElseIf v1 = 13 Then
t1 = "s"
ElseIf v1 = 14 Then
t1 = "d"
ElseIf v1 = 15 Then
t1 = "f"
ElseIf v1 = 16 Then
t1 = "g"
ElseIf v1 = 17 Then
t1 = "h"
ElseIf v1 = 18 Then
t1 = "j"
ElseIf v1 = 19 Then
t1 = "k"
ElseIf v1 = 20 Then
t1 = "l"
ElseIf v1 = 21 Then
t1 = "z"
ElseIf v1 = 22 Then
t1 = "x"
ElseIf v1 = 23 Then
t1 = "c"
ElseIf v1 = 24 Then
t1 = "v"
ElseIf v1 = 25 Then
t1 = "b"
ElseIf v1 = 26 Then
t1 = "n"
ElseIf v1 = 27 Then
t1 = "m"
ElseIf v1 = 28 Then
t1 = "!"
ElseIf v1 = 29 Then
t1 = "?"
EndIf
If v2 = 1 Then
t2 = " "
ElseIf v2 = 2 Then
t2 = "q"
ElseIf v2 = 3 Then
t2 = "w"
ElseIf v2 = 4 Then
t2 = "e"
ElseIf v2 = 5 Then
t2 = "r"
ElseIf v2 = 6 Then
t2 = "t"
ElseIf v2 = 7 Then
t2 = "y"
ElseIf v2 = 8 Then
t2 = "u"
ElseIf v2 = 8 Then
t2 = "u"
ElseIf v2 = 9 Then
t2 = "i"
ElseIf v2 = 10 Then
t2 = "o"
ElseIf v2 = 11 Then
t2 = "p"
ElseIf v2 = 12 Then
t2 = "a"
ElseIf v2 = 13 Then
t2 = "s"
ElseIf v2 = 14 Then
t2 = "d"
ElseIf v2 = 15 Then
t2 = "f"
ElseIf v2 = 16 Then
t2 = "g"
ElseIf v2 = 17 Then
t2 = "h"
ElseIf v2 = 18 Then
t2 = "j"
ElseIf v2 = 19 Then
Благодаря этому примеру, мы ещё раз убеждаемся, что SmallBasic- не язык. В оригинале программы есть ещё 350 строк отборного говнокода такого плана.
−91
[Embed(source = "/assets/video_preview/VideoSlideThumb.png")]
public static const VIDEO_PREVIEW: Class;
public static function get videoPreviewBD(): BitmapData
{
var image : Bitmap = new VIDEO_PREVIEW ();
return image.bitmapData.clone();
}
Когда-то давно бытовала такая пословица: What Intel giveth Microsoft taketh away. Но похоже что переходное красное знамя подхватили и в других организациях по-меньше.
+135
void *list_find_data(struct node *llist, void *data, int (*cmp_func)(void *, void *))
{
struct node* it_node = NULL;
if (NULL != cmp_func)
{
for(it_node = llist; (NULL != it_node); it_node = it_node->next)
{
if (NULL != it_node->data)
{
if (0 == cmp_func(data, it_node->data))
{
break;
}
}
}
}
return ((NULL != it_node) && (NULL != it_node->data)) ? it_node->data : NULL;
}
Велосипедисты жгут. О glibопараше не наслышаны.
−863
SELECT *
FROM session s
WHERE s.platform IS NOT NULL
GROUP BY s.user_id
HAVING MAX(s.open_utc)
Но хоть можно понять что сказать пытались, и на том спасибо.
+55
void input (char inpt [64])
{
for (;;)
{
int i(0);
cin >> inpt;
i ++;
if (inpt[i] == '\n')
inpt[i] = '\0';break;
}
}
+156
<?php
class view {
protected $dir; //templates directory
protected $lang; //language
protected $authorized;
protected $user;
protected function getCache($template) {
//return false; //uncomment for developing
if (!isset($_SESSION['cache_' . $template])) return false;
return $_SESSION['cache_' . $template];
}
protected function addCache($template, $content) {
$_SESSION['cache_' . $template] = $content;
}
public function __construct($dir, localization $lang, user $user) {
$this->dir = $dir;
$this->authorized = (bool) $user->authorized;
$this->user = $user;
$this->lang = $lang;
}
public function invoke($template, $params = [], $return = false, $quests = []) { //can be called w/o params
$filename = ROOT . '/' . $this->dir . '/tpl/' . $template . '.tpl';
$lang = $this->lang->getData();
$content = $this->getCache($template);
if (!$content) {
$f = fopen($filename, 'a+');
$content = fread($f, (filesize($filename) > 0 ? filesize($filename) : 1));
$this->addCache($template, $content);
}
foreach ($params as $key => $value) {
$content = str_ireplace('{{' . $key . '}}', $value, $content);
}
preg_match_all("@{{:([a-z0-9_]+?)}}@sui", $content, $localization);
$localization = $localization[1];
foreach ($localization as $value) {
$content = str_ireplace('{{:' . $value . '}}', $lang[$value], $content);
} //applying lang
foreach ($quests as $key => $value) {
preg_match_all("@{\?$key=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
while (!empty($matches[0])) {
$content = str_replace($matches[0][0], $matches[1][0], $content);
preg_match_all("@{\?$key=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
}
preg_match_all("@{\?$key=((?!$value).+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
while (!empty($matches[0])) {
$content = str_replace($matches[0][0], "", $content);
preg_match_all("@{\?$key=((?!$value).+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $matches);
}
}
preg_match_all("@{\?access=([a-z0-9]+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $perms);
while (!empty($perms[0])) {
foreach ($perms[1] as $value) {
if ($this->user->canAccess($value))
$content = preg_replace("@{\?access=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", "$1", $content);
else $content = preg_replace("@{\?access=$value\?}(((?!{\?.+\?}).)*?){\?\?}@sui", "", $content);
}
preg_match_all("@{\?access=([a-z0-9]+?)\?}(((?!{\?.+\?}).)*?){\?\?}@sui", $content, $perms);
}
$content = preg_replace("@{\?authorized=((?!" . (int) $this->authorized . ").+?)\?}(.+?){\?\?}@sui", "", $content);
$content = preg_replace("@{\?authorized=" . (int) $this->authorized . "\?}(.+?){\?\?}@sui", "$1", $content);
$content = preg_replace("@{\?(.+?)\?}(.+?){\?\?}@sui", "", $content);
$content = str_ireplace('{{DIR}}', '/' . $this->dir, $content); //replacing DIR param
$content = str_ireplace('{{URI}}', urlencode(other::filter($_SERVER['REQUEST_URI'])), $content); //replacing URI param
$content = str_ireplace('{{HTTP_HOST}}', $_SERVER['HTTP_HOST'], $content); //replacing HTTP_HOST param
$content = preg_replace("@{\?((.+?)|(.+?){0})\?}@sui", "", $content);
if (!$return) echo $content;
return $content;
}
}
?>
Мой шаблонизатор. Детям и беременным женщинам не смотреть.
+156
<?php
class ACL
{
var $perms = array(); // Массив : Содержит привилегия текущего пользователя
var $userID = 0; // Целое число : Содержит ID текущего пользователя
var $userRoles = array(); // Массив : Содержат роли текущего пользователя
function __constructor($userID = '')
{
if ($userID != '')
{
$this->userID = floatval($userID);
} else {
$this->userID = floatval($_SESSION['userID']);
}
$this->userRoles = $this->getUserRoles('ids');
$this->buildACL();
}
function ACL($userID='')
{
$this->__constructor($userID);
}
?>
Конструктор
__constructor() предназначен для того, чтобы инициализировать объект при создании экземпляра класса ACL. Он вызывается автоматически после вот этой записи: new ACL();
Не сразу понял, что логика тут есть, но какая-то кривая