- 1
- 2
- 3
- 4
- 5
private unsafe bool IsOptionalOutParamSet(out Guid param)
{
fixed (Guid* guidPtr = ¶m)
return (IntPtr) guidPtr != IntPtr.Zero;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+131
private unsafe bool IsOptionalOutParamSet(out Guid param)
{
fixed (Guid* guidPtr = ¶m)
return (IntPtr) guidPtr != IntPtr.Zero;
}
+4
int DataBase::garbageCollector(string filename){
fstream from(filename.c_str());
fstream from0((filename+".index").c_str());
Index x;
Data d;
char *a/*,*b*/;
int oldpos = 0 ;
bool done = false;
from.seekg(0,ios::end);
int dbend = static_cast<int>(from.tellp());
from0.seekg(0,ios::end);
int indexend = static_cast<int>(from0.tellp());
if(dbend == BlockSize || indexend == IndexSize){
from.close();
from0.close();
return 0;
}
from.seekg(0,ios::beg);
from0.seekg(0,ios::beg);
while(true){
from0 >> x;
if(from0.eof())break;
if(!x.Num()){
int count = dbend - x.Pointer() - BlockSize;
int count0 = indexend - (static_cast<int>(from0.tellp())+1);
from.seekg(x.Pointer()+BlockSize);
a = new char[count];
from.read(a,count);
from.seekp(x.Pointer());
from.write(a,count);
delete a;
a = new char[count0];
from0.seekp(1,ios::cur);
int test = from0.tellp();
from0.read(a,count0);
from0.clear();
from0.seekp(indexend - count0 - IndexSize,ios::beg);
test = from0.tellp();
from0.write(a,count0);
test = from0.tellp();
delete a;
ofstream to("tmp.base",ios::trunc),to0("tmp.index",ios::trunc);
a = new char[dbend - BlockSize];
from.seekg(0,ios::beg);
from.read(a,dbend - BlockSize);
to.write(a,dbend - BlockSize);
delete a;
a = new char[indexend - IndexSize];
from0.seekg(0,ios::beg);
test = from0.tellp();
from0.read(a,indexend - IndexSize);
to0.write(a,indexend - IndexSize);
delete a;
from.close();
from0.close();
if(remove(filename.c_str()) || rename("tmp.base",filename.c_str())) return -1;
if(remove((filename+".index").c_str()) || rename("tmp.index",(filename+".index").c_str())) return -1;
oldpos = indexend - count0 - IndexSize;
done = true;
break;
}
}
if(done){
from0.open((filename+".index").c_str());
while(true){
from0 >> x;
if(from0.eof())break;
if(x.Pointer() > static_cast<unsigned>((oldpos/23)*BlockSize) ){
x.Pointer(x.Pointer()-BlockSize);
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
}
else{
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
from0.clear();
}
}
}
return 0;
}
Собираем пустые блоки
+6
int DataBase::split(fstream& from,fstream& from0,unsigned int p){
int pos0 = static_cast<int>(from.tellp());
char *a,*b;
Data d,d0;
Index x,x0;
from.clear();
from.seekp(0,ios::end);
int PosEnd = static_cast<int>(from.tellp());
PosEnd -=static_cast<int>(p);
a = new char[PosEnd];
from.seekp(p,ios::beg);
from.read(a,PosEnd);
from.seekp(p+BlockSize,ios::beg);
from.write(a,PosEnd);
from.seekp(p+BlockSize,ios::beg);
b = a+5*RecordSize;
from.write(b,RecordSize*5);
for (int i = 0; i < 5; ++i){
from << d;
}
from.seekp(p+RecordSize*5,ios::beg);
for (int i = 0; i < 5; ++i){
from << d;
}
from.seekg(p+RecordSize*4);
from >> d;
int newmax = d.Id();
from0.seekp(0,ios::end);
int indexend =static_cast<int>(from0.tellp());
from0.seekg(0,ios::beg);
while(true){
from0 >> x;
if(from0.eof())break;
if(x.Pointer() == p){
int oldpos = static_cast<int>(from0.tellp());
oldpos++;
int count = indexend - oldpos;
char *c = new char[count];
from0.seekg(1,ios::cur);
from0.read(c,count);
from0.seekp(oldpos,ios::beg);
x0.Max(x.Max());
x0.Num(5);
x0.Pointer(p + BlockSize);
from0 << x0;
from0.write(c,count);
from0.seekp(oldpos - IndexSize,ios::beg);
x.Max(newmax);
x.Num(5);
from0 << x;
delete c;
from.clear();
from0.seekp(0,ios::beg);
break;
}
}
from.clear();
bool first = false;
while(true){
from0 >> x;
if(from0.eof())break;
if(x.Pointer() > p ){
if(!first){
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
from0.clear();
first = true;
continue;
}
x.Pointer(x.Pointer()+BlockSize);
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
}
else{
from0.seekp(-(IndexSize-1),ios::cur);
from0 << x;
int test = from0.tellp();
from0.clear();
}
}
from.clear();
from.seekp(pos0);
delete a;
//delete b;
return 0;
}
Нарезаем
+81
public boolean hasNext() {
if (vectorIndex == vector.size())
return false;
return true;
}
public Object next() {
try {
return new Double(vector.getElement(vectorIndex));
}
catch(OutOfBoundsException e) {
throw new RuntimeException(e);
}
finally {
vectorIndex++ ;
}
}
Такой вот итератор у начинающего жавера...
+10
void ImageArea::saveConf(bool def)
{
static bool fp = true;
static QString filename = QString("default.conf");
if(!def){
filename = QFileDialog::getSaveFileName(this, tr("Save config"), "", tr("Config files (*.conf)"));
if(fp){
QFile file(filename);
if(file.open(QFile::WriteOnly)){
QTextStream str(&file);
str << crop[0].x() << " " << crop[0].y() << "\n";
str << crop[1].x() << " " << crop[1].y() << "\n";
str << square[0].x() << " " << square[0].y() << "\n";
str << square[1].x() << " " << square[1].y() << "\n";
str << square[2].x() << " " << square[2].y() << "\n";
QMessageBox::information(this, tr("Next step"), tr("Put 3 points then press Save again"));
}else{
QMessageBox::warning(this, tr("Error"), tr("Can not open a file"));
}
fp = false;
}else{
QFile file(filename);
if(file.open(QFile::Append)){
QTextStream str(&file);
str << square[0].x() << " " << square[0].y() << "\n";
str << square[1].x() << " " << square[1].y() << "\n";
str << square[2].x() << " " << square[2].y() << "\n";
}else{
QMessageBox::warning(this, tr("Error"), tr("Can not open a file"));
}
fp = true;
}
}else{
QFile file(filename);
if(file.open(QFile::WriteOnly)){
QTextStream str(&file);
str << conf.crop[0].x() << " " << conf.crop[0].y() << "\n";
str << conf.crop[1].x() << " " << conf.crop[1].y() << "\n";
str << conf.square[0].x() << " " << conf.square[0].y() << "\n";
str << conf.square[1].x() << " " << conf.square[1].y() << "\n";
str << conf.square[2].x() << " " << conf.square[2].y() << "\n";
str << conf.square0[0].x() << " " << conf.square0[0].y() << "\n";
str << conf.square0[1].x() << " " << conf.square0[1].y() << "\n";
str << conf.square0[2].x() << " " << conf.square0[2].y() << "\n";
}
}
}
Сохраняем конфиг в джва захода.
+160
function casinoGamesParser($body, $infoBoxyLink)
{
// try ruletka
$ruletkaReplaceCode = read_file('system/application/views/site/boxy-rul.php');
$ruletkaReplaceCode = str_replace('<?php echo $boxylink;?>', $infoBoxyLink, $ruletkaReplaceCode);
$ruletkaReplaceCode = str_replace('<?php echo site_url();?>', site_url(), $ruletkaReplaceCode);
$delimiterFirst = "<p>фун_рулетка(";
$delimiterLast = ")енд</p>";
$keyword = between2finer($body, $delimiterFirst, $delimiterLast);
if (!empty($keyword)) $ruletkaReplaceCode = str_replace('<?php echo $keyword ?>', $keyword, $ruletkaReplaceCode);
if (!empty($keyword)) return str_replace($delimiterFirst.$keyword.$delimiterLast, $ruletkaReplaceCode.$keyword, $body);
// try poker
$pokerReplaceCode = read_file('system/application/views/site/boxy-poker.php');
$pokerReplaceCode = str_replace('<?php echo $boxylink;?>', $infoBoxyLink, $pokerReplaceCode);
$pokerReplaceCode = str_replace('<?php echo site_url();?>', site_url(), $pokerReplaceCode);
$delimiterFirst = "фун_покер(";
$delimiterLast = ")енд";
$keyword = between2finer($body, $delimiterFirst, $delimiterLast);
if (!empty($keyword)) $pokerReplaceCode = str_replace('<?php echo $keyword ?>', $keyword, $pokerReplaceCode);
if (!empty($keyword)) return str_replace($delimiterFirst.$keyword.$delimiterLast, $pokerReplaceCode.$keyword, $body);
// if nothing found - return original body
return $body;
}
Берут РНР файл как текстовый в переменную и заменяют в нем вставки РНР кода <?php echo $keyword ?>. Получается РНР парсит свой код str_replace*ом. Ну вобщем неплохо получилось запутать китайских шпионов!
+13
if(ortho){
if( abs(e->x() - line.p1().x() ) * 2 < abs( e->y() - line.p1().y() ) ){
y = e->y();
x = line.p1().x();
}else if(abs(e->x() - line.p1().x() ) > 2 * abs( e->y() - line.p1().y() )){
x = e->x();
y = line.p1().y();
}else if(abs(e->x() - line.p1().x() ) * 2 > abs( e->y() - line.p1().y() ) &&
abs(e->x() - line.p1().x() ) < abs( e->y() - line.p1().y() )){
if((e->x() < line.p1().x() && e->y() < line.p1().y()) || (e->x() > line.p1().x() && e->y() < line.p1().y())){
x = e->x();
y = line.p1().y() - abs(line.p1().x() - e->x());
}else if((e->x() > line.p1().x() && e->y() > line.p1().y()) || (e->x() < line.p1().x() && e->y() > line.p1().y())){
x = e->x();
y = line.p1().y() + abs(line.p1().x() - e->x());
}
}else if(abs(e->x() - line.p1().x() ) < 2 * abs( e->y() - line.p1().y() ) &&
abs(e->x() - line.p1().x() ) > abs( e->y() - line.p1().y() )){
if((e->x() < line.p1().x() && e->y() < line.p1().y()) || (e->x() < line.p1().x() && e->y() > line.p1().y())){
y = e->y();
x = line.p1().x() - abs(line.p1().y() - e->y());
}else if((e->x() > line.p1().x() && e->y() > line.p1().y()) || (e->x() > line.p1().x() && e->y() < line.p1().y())){
y = e->y();
x = line.p1().x() + abs(line.p1().y() - e->y());
}
}else{
x = e->x();
y = e->y();
}
+129
#region Work with massive slovo
public string sFileNameMassiveSlovar = "";
public bool flChangeSlovo = false;
public int nCountSavedSlovo { get; private set; }
public int nCountAllSlovo { get; private set; }
public int nCountAddSlovo { get; private set; }
public void ClearMassiveSlovo()
{
slovo = slovo.Select(n => (byte)0).ToArray();
}
public int GetCountAllSlovo()
{
int npock = nLengthSlovo;
return slovo.Where((n, index) => index % npock == 0 && n != 0).Count();
}
public bool WriteMassiveSlovo()
{
bool res = false;
FileStream fs = null;
try
{
fs = File.Open(sFileNameMassiveSlovar, FileMode.Create, FileAccess.Write);
if (fs != null)
{
fs.Write(slovo, 0, nSizeMassiveSlova);
}
res = true;
}
catch (Exception e1)
{
res = false;
System.Windows.Forms.MessageBox.Show(e1.Message);
}
finally
{
if (fs != null) fs.Close();
}
return res;
}
#endregion
+171
public abstract class BaseDateTime
extends AbstractDateTime
implements ReadableDateTime, Serializable {
/** The millis from 1970-01-01T00:00:00Z */
private volatile long iMillis;
/** The chronology to use */
private volatile Chronology iChronology;
/////////////////////////////////////////////////////////////////
/*
* DateTime is thread-safe and immutable, provided that the Chronology is as well.
* All standard Chronology classes supplied are thread-safe and immutable.
*
* @see MutableDateTime
*/
public final class DateTime
extends BaseDateTime
Любителям joda-time.
Cмущает меня этот volatile, который приходит в немутабельный класс от родителя.
+150
public static function getDeferredSubsCardExpirationDate($date) {
$ts = strtotime($date);
return mktime(date('H', $ts), date('i', $ts), date('s', $ts), date('m', $ts), date('d', $ts), date('Y', $ts) + Constants::GIFT_CARD_EXPIRATION_PERIOD);
}
ОУКЕЙ