- 1
int cutPosition = sb.ToString().IndexOf(" \r\n ");
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+112
int cutPosition = sb.ToString().IndexOf(" \r\n ");
Коммерческий проект :)
+15
system("PAUSE")
Красивое, оптимальное, и самое главное, кроссплатформенное решение для ожидания нажатия клавиши.
http://habrahabr.ru/post/147104/
Предупреждая вопрос "где здесь с++", отвечу - автор считал, что он пишет на с++, и даже использовал пару конструкций оттуда - перегрузку функций и new/delete.
+15
#pragma once
#include <assert.h>
template<typename T>
inline T notNull(T arg)
{
assert(arg!=NULL);
return arg;
}
/*
//example:
class AnotherClass;
class SomeClass
{
AnotherClass * m_another;
//...
SomeClass(AnotherClass * another, /*skipped*/) : m_another(notNull(another)), /*skipped*/;
}
*/
Мелочь, конечно же, но всё-таки чушь, несмотря на пользу.
+19
// хелпер чтобы конвертить типы строк
template <class S1, class S2>
struct str_convert {
static S1 conv(S2 const & s2) { return str_convert<S2, S1>::conv(s2); } // по умолчанию ищет специализацию для пары S2, S1
static S2 conv(S1 const & s1) { return str_convert<S2, S1>::conv(s1); }
};
// специализация, чтобы не конвертить одно в одно
template <class S>
struct str_convert<S, S> {
static S const & conv(S const & s) { return s; };
};
// специализация, чтобы конвертить std::string <-> std::wstring
template <>
struct str_convert<std::string, std::wstring> {
static std::string conv(std::wstring const & ws) { return boost::locale::conv::utf_to_utf<char>(ws); }
static std::wstring conv(std::string const & s) { return boost::locale::conv::utf_to_utf<wchar_t>(s); }
};
// специализация QString <-> std::string
// skipped
template <class StringType = std::string>
struct some
{
typedef StringType string_type;
typedef std::string utf8_string_type;
some(string_type const & s = string_type())
: inner_string_(s)
{}
template <class S>
some(S const & s)
: inner_string_(str_convert<S, string_type>::conv(s))
{}
string_type inner_string_;
};
int main()
{
std::string s = "hello!";
some<> test0(s); // ok
some<> test2("hello!"); // ха-ха, вот еще, пытаться самостоятельно привести к std::string, пиши специализацию для массивов, сука!
return 0;
}
сегодня ради красоты передачи "literal" в конструктор писал говноспециализации для PodType[N]
+58
$arrNotViewDeathWindow = array(
'/reklama/press/index.php' => '1',
'/reklama/press/' => '1',
'/reklama/product/index.php' => '1',
'/reklama/product/' => '1',
'/about/poll/' => '1',
'/about/poll/index.php' => '1',
'/about/poll/result.php' => '1',
'/reklama/product/orders_list.php' => '1',
);
if(!$arrNotViewDeathWindow[$_SERVER['SCRIPT_NAME']]) ...
Кусок кода из отображения всплывающего окна на сайте на всех страницах кроме...
+23
if(this==NULL)
return;
+155
switch(navigator.appName) {
case "Microsoft Internet Explorer":
Key = "event.ctrlKey && event.keyCode == 13";
document.onkeydown = get_key;
break;
case "Netscape":
Key = "(e.modifiers == 2 && e.which == 10) || (e.ctrlKey && e.which == 13)";
document.captureEvents(Event.KEYDOWN);
document.onkeydown = get_key;
break;
}
}
function get_key(e) {
if (eval(Key)) {
if (check_postform()){
check_submit();
document.postform.submit();
submit_once(document.postform);
} else {return false}
}
http://forum.ixbt.com/
+77
/**
* Returns the an array (length 1) containing the checkbox menu item
* label or null if the checkbox is not selected.
* @see ItemSelectable
*/
public synchronized Object[] getSelectedObjects() {
if (state) {
Object[] items = new Object[1];
items[0] = label;
return items;
}
return null;
}
java.awt.CheckboxMenuItem
+74
reader = new BufferedReader(new FileReader(file));
//null means file end
while ((tempString = reader.readLine()) != null) {
if(tempString !=null && tempString.indexOf('=')>0){
sheet.addCell(new Label(KEY_COLUMN,++ROW, tempString.substring(0,tempString.indexOf('='))));
sheet.addCell(new Label(ENGLISH_COLUMN,ROW, tempString.substring(tempString.indexOf('=')+1)));
}
}
reader.close();
Вот так мы парсим файл *.properties в Java.
+54
/**
* Грабли - наше всьо
* @return string
*/
function toPage()
{
...
}
прекрасно задокументированная функция