- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
list<int> l;
//...
for(int i=0;i<l.size();++i)
{
auto it=l.begin();
advance(it, i);
int item=*it;
//...
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+997
list<int> l;
//...
for(int i=0;i<l.size();++i)
{
auto it=l.begin();
advance(it, i);
int item=*it;
//...
+163
Электронная почта (e-mail) - если указано, то проверяем корректность
p_email = document.myform.email.value.toString();
if (p_email != "") {
t = p_email.indexOf("@");
if((p_email.indexOf(".") == -1) || (t == -1) || (t < 1) || (t > p_email.length - 5) || (p_email.charAt(t - 1) == '.') || (p_email.charAt(t + 1) == '.')) {
alert("Некорректно указан E-mail !");
document.myform.email.focus();
return false;
}
}
http://www.whatis.ru/razn/razn14.shtml
+80
getBtnContent().setEnabled(enable);
if (getGridConfig().isContentEnabled()) {
getBtnContent().setEnabled(enable);
}
Программист со стажем, всегда хочет быть уверен что кнопка будет доступна на 150%
+116
<Grid Grid.Row="2" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="0" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[0]}"/>
<ContentPresenter Grid.Row="0" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[1]}"/>
<ContentPresenter Grid.Row="0" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[2]}"/>
<ContentPresenter Grid.Row="1" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[3]}"/>
<ContentPresenter Grid.Row="1" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[4]}"/>
<ContentPresenter Grid.Row="1" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[5]}"/>
<ContentPresenter Grid.Row="2" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[6]}"/>
<ContentPresenter Grid.Row="2" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[7]}"/>
<ContentPresenter Grid.Row="2" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[8]}"/>
<ContentPresenter Grid.Row="3" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[9]}"/>
<ContentPresenter Grid.Row="3" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[10]}"/>
<ContentPresenter Grid.Row="3" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[11]}"/>
<ContentPresenter Grid.Row="4" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[12]}"/>
<ContentPresenter Grid.Row="4" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[13]}"/>
<ContentPresenter Grid.Row="4" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[14]}"/>
<ContentPresenter Grid.Row="5" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[15]}"/>
<ContentPresenter Grid.Row="5" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[16]}"/>
<ContentPresenter Grid.Row="5" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[17]}"/>
<ContentPresenter Grid.Row="6" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[18]}"/>
<ContentPresenter Grid.Row="6" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[19]}"/>
<ContentPresenter Grid.Row="6" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[20]}"/>
</Grid>
+141
char *zamena(int m)
{
char *s;
int a,b,c;
a = m / 100;
b=(m / 10)% 10;
c=m % 10;
if (a>0)
switch (a)
{
case 1: s=s+"сто ";
case 2: s=s+"двести ";
case 3: s=s+"триста ";
case 4: s=s+"четыреста ";
case 5: s=s+"пятьсот ";
case 6: s=s+"шестьсот ";
case 7: s=s+"семьсот ";
case 8: s=s+"восемьсот ";
case 9: s=s+"девятьсот ";
}
if (b==1)
switch (c)
{
case 1: s=s+"одиннадцать ";
case 2: s=s+"двенадцать ";
case 3: s=s+"тринадцать ";
case 4: s=s+"четырнадцать ";
case 5: s=s+"пятнадцать ";
case 6: s=s+"шестнадцать ";
case 7: s=s+"семнадцать ";
case 8: s=s+"восемнадцать ";
case 9: s=s+"девятнадцать ";
}
else
switch (b)
{
case 2: s=s+"двадцать ";
case 3: s=s+"тридцать ";
case 4: s=s+"сорок ";
case 5: s=s+"пятьдесят ";
case 6: s=s+"шестьдесят ";
case 7: s=s+"семьдесят ";
case 8: s=s+"восемьдесят ";
case 9: s=s+"девяносто ";
}
if (b!=1 && c>0)
switch (c)
{
case 1: s=s+"один ";
case 2: s=s+"два ";
case 3: s=s+"три ";
case 4: s=s+"четыре ";
case 5: s=s+"пять ";
case 6: s=s+"шесть ";
case 7: s=s+"семь ";
case 8: s=s+"восемь ";
case 9: s=s+"девять ";
}
return s;
}
Перевод целого числа в строку.
+161
$searchCondition1 = '';
$searchCondition2 = '';
$searchCondition3 = '';
$flag = false;
$sql = 'SELECT f.flight_id,
(SELECT city
FROM airports
WHERE airport_id = f.from) as _from,
(SELECT city
FROM airports
WHERE airport_id = f.to) as _to,
f.flight_date as fdate,
f.flight_time,
f.distance,
p.plain_name as plain
FROM flight f JOIN planes p
ON f.plain_id = p.plain_id
WHERE ';
$fields = 0;
if($_POST['txtSearch']){
if($_POST['txtFrom'] != ''){
$searchCondition1 = " city = '".$_POST['txtFrom']."'";
$flag = true; // set flag to TRUE
$fields++;
}
if($_POST['txtTo'] != ''){ // if To field is not empty
$searchCondition2 = " city = '".$_POST['txtTo']."'";
$flag = true; // set flag to TRUE
$fields++;
}
if ($_POST['txtDate'] != ''){ // if Date field is not empty
$searchCondition3 = " DATE(f.flight_date) = '".$_POST['txtDate']."'";
$fields++; // and inc
}
if($fields == 0){
echo "<br/><div style=\"color:red\">Please, enter at least one filed to search</div>";
}else{
if($searchCondition1 != '' && $searchCondition2 == ''){
$sql .= " f.from IN (SELECT airport_id
FROM airports
WHERE ".$searchCondition1.")";
}
if($searchCondition1 == '' && $searchCondition2 != ''){
$sql .= " f.to IN (SELECT airport_id
FROM airports
WHERE ".$searchCondition2.")";
}
if($searchCondition1 != '' && $searchCondition2 != ''){
$sql .= " f.from IN (SELECT airport_id
FROM airports
WHERE ".$searchCondition1.")
AND f.to IN (SELECT airport_id
FROM airports
WHERE ".$searchCondition2.")";
}
if($searchCondition3 != ''){
if($flag){
$sql .= " AND ".$searchCondition3;
}else{
$sql .= $searchCondition3;
}
}
include_once('database.php');
$db = createPDO();
$result = $db->query($sql);
echo '<table>
<tr>
<th>
From
</th>
<th>
To
</th>
<th>
Flight Date
</th>
<th>
Flight Time
</th>
<th>
Distance
</th>
<th>
Plane
</th>
<th>
Action
</th>
</tr>'; // create an HTML table with headers
while($row = $result->fetch()){...}
Ищем в табличке в зависимости от заполненных полей в форме
+162
template <
typename PropertyOwner // Класс владельца
>
class properties {
public:
// Получить указатель на владельца по указателю на свойство
static PropertyOwner * owner( void * property ) {
int aai = (int)&(((PropertyOwner*)0)->__properties);
return (PropertyOwner *)((char*)property - aai);
}
};
/**
* Шаблон класса свойства
*/
template <
typename PropertyOwner, // Класс владельца
typename PropertyType, // Тип свойства
PropertyType (PropertyOwner::*getter)(), // Геттер
void (PropertyOwner::*setter)(PropertyType) > // Сеттер
class property {
public:
/**
* Чтение свойства - вызов геттера
*/
operator PropertyType() {
return (properties<PropertyOwner>::owner( this )->*getter)();
}
/**
* Запись в свойство - вызов сеттера
*/
void operator = ( const PropertyType & value ) {
(properties<PropertyOwner>::owner( this )->*setter)( value );
}
};
// Макросы для удобного определения свойств /////////
/**
* Начать объявления свойств в классе cls
*/
#define properties_start(cls) union { properties<cls> __properties;
/**
* Закончить объявление свойств в классе cls
*/
#define properties_end() };
/**
* Объявить свойство в классе cls типа type c геттером getter и сеттером setter
*/
#define property(cls,type,getter,setter) property<cls,type,&cls::getter,&cls::setter>
http://www.codenet.ru/progr/cpp/cpp-properties.php
−99
# Work fine only on call with has_many association
def self.new_from_params options
new_rule = Rule.new
return nil if new_rule.project_id.nil?
rule = Rule.find_by_id options[:rule_id]
if rule.nil? or (new_rule.project.id != rule.project.id)
rule = Rule.new
end
new_rule.rule_id = options[:rule_id]
new_rule.users = (rule.users.to_a + options[:users].to_a).uniq
new_rule.statuses = (rule.statuses.to_a + options[:statuses].to_a).uniq
new_rule.tags = (rule.tags.to_a + options[:tags].to_a).uniq
new_rule.grouped_by = options[:grouped_by].presence || rule.grouped_by.presence
new_rule.sorted_by = options[:sorted_by].presence || rule.sorted_by.presence
new_rule.search = options[:search].presence || rule.search.presence
new_rule.period_start = options[:period_start].presence || rule.period_start.presence
new_rule.period_end = options[:period_end].presence || rule.period_end.presence
new_rule
end
−111
public function cloneString(str:String):String {
if(str == null) return null;
_byteArray.position = 0;
_byteArray.writeUTF(str);
_byteArray.position = 0;
var res:String = _byteArray.readUTF();
// fuck yeah!
return res;
}
суровые сибирские программисты клонируют строки like a pro
+161
...
public function getLocations($fresh = 0)
{
$tld =& $this->varGet('tld');
$domain =& $this->varGet('domain');
// if website is viewed via IP
$noWWWButIP =& $this->varGet('noWWWButIP');
$memCacheKey = 'getLocations';
if (!$fresh) {
// already fetched and stored in vars?
if (is_array($this->varGet('arrLocations')))
$arrLocations = $this->varGet('arrLocations');
// lets try fetching from memcache
else
$arrLocations = kd()->lib('kdCache')->get($memCacheKey);
}
// regenerate
unset($arrLocations);
if (!is_array($arrLocations)) {
...
Кэшируем))