- 1
- 2
- 3
- 4
foreach my $i (0 .. (scalar @{ $PARAMS{Input} } - 1) )
{
@{ $PARAMS{Input} }[$i] = expand_filename(@{ $PARAMS{Input} }[$i]);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−161
foreach my $i (0 .. (scalar @{ $PARAMS{Input} } - 1) )
{
@{ $PARAMS{Input} }[$i] = expand_filename(@{ $PARAMS{Input} }[$i]);
}
Такая то экспрессия
+145
int boolToInt(bool b)
{
bool * boolPtr = &b;
char * boolToCharPtr = reinterpret_cast<char *>(boolPtr);
char * resultCharPtr;
resultCharPtr = (char*) malloc(4);
for (int i = 0; i < sizeof(int); i++)
{
if (i == 0)
{
resultCharPtr[i] = boolToCharPtr[0];
}
if (i == 1)
{
resultCharPtr[i] = 0x00;
}
if (i == 2)
{
resultCharPtr[i] = 0x00;
}
if (i == 3)
{
resultCharPtr[i] = 0x00;
}
}
int * intPtr = reinterpret_cast<int *> (resultCharPtr);
return *intPtr;
}
Удобная функция для конвертации bool в int
−93
# Source: python3.4/distutils/dir_util.py
# cache for by mkpath() -- in addition to cheapening redundant calls,
# eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
_path_created = {}
# I don't use os.makedirs because a) it's new to Python 1.5.2, and
# b) it blows up if the directory already exists (I want to silently
# succeed in that case).
def mkpath(name, mode=0777, verbose=1, dry_run=0):
"""Create a directory and any missing ancestor directories.
If the directory already exists (or if 'name' is the empty string, which
means the current directory, which of course exists), then do nothing.
Raise DistutilsFileError if unable to create some directory along the way
(eg. some sub-path exists, but is a file rather than a directory).
If 'verbose' is true, print a one-line summary of each mkdir to stdout.
Return the list of directories actually created.
"""
global _path_created
# Detect a common bug -- name is None
if not isinstance(name, basestring):
raise DistutilsInternalError, \
"mkpath: 'name' must be a string (got %r)" % (name,)
# XXX what's the better way to handle verbosity? print as we create
# each directory in the path (the current behaviour), or only announce
# the creation of the whole path? (quite easy to do the latter since
# we're not using a recursive algorithm)
name = os.path.normpath(name)
created_dirs = []
if os.path.isdir(name) or name == '':
return created_dirs
if _path_created.get(os.path.abspath(name)):
return created_dirs
...
Мало того, что метод жив на основании того, что os.makedirs был добавлен только в Python 1.5.2 (мама родная, 2.7 скоро закопаем, а говно всё тянется), так его ещё и умудрились наиндусить на 60 строк кода, да ещё и ХХХ секцию аккуратно положили. Ладно, чего это я придираюсь... Ах да, оно кеширует уже созданные директории, так что если создать папку и удалить её, второй раз её уже никак не создашь...
+152
if (a == 10)
{
<какие-то действия>
}
else
{
<один в один те же самые действия>
}
Безысходность.
+53
class CClass
{
//...
boost::shared_ptr<CTestData> mpTestData;
//...
};
void CClass::setTestData(boost::shared_ptr<CTestData> pTestData)
{
if(pTestData.use_count() == 0)
{
mpTestData.reset();
}
else
{
mpTestData = pTestData;
}
}
+156
class ChargifyNotFoundException extends ChargifyException {
var $errors;
var $http_code;
public function ChargifyNotFoundException($http_code, $error) {
$this->http_code = $http_code;
$message = '';
$this->errors = array();
foreach ($error as $key=>$value) {
if ($key == 'error') {
$this->errors[] = $value;
$message .= $value . ' ';
}
}
parent::__construct($message, intval($http_code));
}
}
Индусам платят за количество строк
+133
/*Checks whether the path exists and the path is directory, otherwise creates a new directory*/
RET_VALS check_create_directory(const char* const dir_path, void (*print_func)(int, char *,...))
{
RET_VALS ret_val;
struct stat sb;
ret_val = RET_OK;
if (NULL != dir_path)
{
if(NULL != print_func)
{
print_func(DBG_INFO, "%s - Checking %s existence\n", __FUNCTION__, dir_path);
}
else
{
dbgprintln("Checking %s existence", dir_path);
}
if (0 != stat(dir_path, &sb) || (false == S_ISDIR(sb.st_mode)))
{
ret_val |= RET_DIR_MISSING;
if(NULL != print_func)
{
print_func(DBG_INFO, "%s - %s is missing\n", __FUNCTION__, dir_path);
}
else
{
dbgprintln("%s is missing", dir_path);
}
errno = 0;
if (0 == mkdir(dir_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
{
ret_val |= RET_DIR_CREATE_OK;
if(NULL != print_func)
{
print_func(DBG_INFO, "%s - %s is successfully created\n", __FUNCTION__, dir_path);
}
else
{
dbgprintln("%s is successfully created", dir_path);
}
}
else
{
char err_msg[_K];
sprintf(err_msg, "Failed to create %s, error %04d - %s", dir_path, errno, strerror(errno));
ret_val |= RET_DIR_CREATE_FAILED;
//dbg_ffln(DBG_ERROR, "Failed to create %s", dir_path);
if(NULL != print_func)
{
print_func(DBG_INFO, "%s - %s\n", __FUNCTION__, err_msg);
}
else
{
dbgprintln("%s", err_msg);
}
}
}
else
{
ret_val |= RET_DIR_ALREADY_EXIST;
if(NULL != print_func)
{
print_func(DBG_INFO, "%s - %s already exists\n", __FUNCTION__, dir_path);
}
else
{
dbgprintln("%s already exists", dir_path);
}
}
}
else
{
ret_val = RET_DIR_MISSING;
if(NULL != print_func)
{
print_func(DBG_ERROR, "%s - No directory name is provided", __FUNCTION__);
}
else
{
dbgprintln("No directory name is provided");
}
}
return ret_val;
}
Продолжаем раскопки. Вообще весь .с файл можно сюда выложить.
+158
function country_code_to_country( $code ){
$country = '';
if( $code == 'AF' ) $country = 'Afghanistan';
if( $code == 'AX' ) $country = 'Aland Islands';
if( $code == 'AL' ) $country = 'Albania';
if( $code == 'DZ' ) $country = 'Algeria';
if( $code == 'AS' ) $country = 'American Samoa';
if( $code == 'AD' ) $country = 'Andorra';
if( $code == 'AO' ) $country = 'Angola';
if( $code == 'AI' ) $country = 'Anguilla';
if( $code == 'AQ' ) $country = 'Antarctica';
if( $code == 'AG' ) $country = 'Antigua and Barbuda';
if( $code == 'AR' ) $country = 'Argentina';
if( $code == 'AM' ) $country = 'Armenia';
if( $code == 'AW' ) $country = 'Aruba';
if( $code == 'AU' ) $country = 'Australia';
if( $code == 'AT' ) $country = 'Austria';
if( $code == 'AZ' ) $country = 'Azerbaijan';
if( $code == 'BS' ) $country = 'Bahamas the';
if( $code == 'BH' ) $country = 'Bahrain';
if( $code == 'BD' ) $country = 'Bangladesh';
if( $code == 'BB' ) $country = 'Barbados';
if( $code == 'BY' ) $country = 'Belarus';
if( $code == 'BE' ) $country = 'Belgium';
if( $code == 'BZ' ) $country = 'Belize';
if( $code == 'BJ' ) $country = 'Benin';
if( $code == 'BM' ) $country = 'Bermuda';
if( $code == 'BT' ) $country = 'Bhutan';
if( $code == 'BO' ) $country = 'Bolivia';
if( $code == 'BA' ) $country = 'Bosnia and Herzegovina';
if( $code == 'BW' ) $country = 'Botswana';
if( $code == 'BV' ) $country = 'Bouvet Island (Bouvetoya)';
if( $code == 'BR' ) $country = 'Brazil';
if( $code == 'IO' ) $country = 'British Indian Ocean Territory (Chagos Archipelago)';
if( $code == 'VG' ) $country = 'British Virgin Islands';
if( $code == 'BN' ) $country = 'Brunei Darussalam';
if( $code == 'BG' ) $country = 'Bulgaria';
if( $code == 'BF' ) $country = 'Burkina Faso';
if( $code == 'BI' ) $country = 'Burundi';
if( $code == 'KH' ) $country = 'Cambodia';
if( $code == 'CM' ) $country = 'Cameroon';
if( $code == 'CA' ) $country = 'Canada';
if( $code == 'CV' ) $country = 'Cape Verde';
if( $code == 'KY' ) $country = 'Cayman Islands';
if( $code == 'CF' ) $country = 'Central African Republic';
if( $code == 'TD' ) $country = 'Chad';
if( $code == 'CL' ) $country = 'Chile';
if( $code == 'CN' ) $country = 'China';
if( $code == 'CX' ) $country = 'Christmas Island';
if( $code == 'CC' ) $country = 'Cocos (Keeling) Islands';
if( $code == 'CO' ) $country = 'Colombia';
if( $code == 'KM' ) $country = 'Comoros the';
if( $code == 'CD' ) $country = 'Congo';
if( $code == 'CG' ) $country = 'Congo the';
if( $code == 'CK' ) $country = 'Cook Islands';
if( $code == 'CR' ) $country = 'Costa Rica';
if( $code == 'CI' ) $country = 'Cote d\'Ivoire';
if( $code == 'HR' ) $country = 'Croatia';
if( $code == 'CU' ) $country = 'Cuba';
if( $code == 'CY' ) $country = 'Cyprus';
if( $code == 'CZ' ) $country = 'Czech Republic';
if( $code == 'DK' ) $country = 'Denmark';
if( $code == 'DJ' ) $country = 'Djibouti';
if( $code == 'DM' ) $country = 'Dominica';
if( $code == 'DO' ) $country = 'Dominican Republic';
if( $code == 'EC' ) $country = 'Ecuador';
if( $code == 'EG' ) $country = 'Egypt';
if( $code == 'SV' ) $country = 'El Salvador';
if( $code == 'GQ' ) $country = 'Equatorial Guinea';
if( $code == 'ER' ) $country = 'Eritrea';
if( $code == 'EE' ) $country = 'Estonia';
if( $code == 'ET' ) $country = 'Ethiopia';
if( $code == 'FO' ) $country = 'Faroe Islands';
if( $code == 'FK' ) $country = 'Falkland Islands (Malvinas)';
if( $code == 'FJ' ) $country = 'Fiji the Fiji Islands';
if( $code == 'FI' ) $country = 'Finland';
if( $code == 'FR' ) $country = 'France, French Republic';
if( $code == 'GF' ) $country = 'French Guiana';
if( $code == 'PF' ) $country = 'French Polynesia';
----------------------------------------------------------------
if( $code == 'VE' ) $country = 'Venezuela';
if( $code == 'VN' ) $country = 'Vietnam';
if( $code == 'WF' ) $country = 'Wallis and Futuna';
if( $code == 'EH' ) $country = 'Western Sahara';
if( $code == 'YE' ) $country = 'Yemen';
if( $code == 'ZM' ) $country = 'Zambia';
if( $code == 'ZW' ) $country = 'Zimbabwe';
if( $country == '') $country = $code;
return $country;
}
Кто-то очень много старался
+83
TextView v = (TextView)
((RelativeLayout)
((AbsoluteLayout)
((LinearLayout)
((RelativeLayout)(
(LinearLayout)activty.findViewById(R.id.container)).getChildAt(1))
.getChildAt(0))
.getChildAt(element))
.getChildAt(0))
.getChildAt(0);
(Android)
когда нет idшников...
+134
SDL_Rect sr = {
e->outputRect.x,
e->outputRect.y+e->lineHeight*line,
e->outputRect.w,
sr.y + e->lineHeight };