- 1
- 2
- 3
- 4
catch (...)
{
return -__LINE__;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+67
catch (...)
{
return -__LINE__;
}
+135
public CookieContainer GetCookies(string url, string login, string password)
{
try
{
var cookies = new CookieContainer();
string postData = string.Format(@"subaction=dologin&username={0}&password={1}&selected_language=Russian&x=62&y=37", Uri.EscapeDataString(login), Uri.EscapeDataString(password));
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url + "admin.php");
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.CookieContainer = cookies;
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.UserAgent = "Opera/9.80 (Windows NT 6.1; U; ru) Presto/2.10.289 Version/12.01";
httpWebRequest.ServicePoint.Expect100Continue = false;
byte[] ByteQuery = System.Text.Encoding.UTF8.GetBytes(postData);
httpWebRequest.ContentLength = ByteQuery.Length;
Stream QueryStream = httpWebRequest.GetRequestStream();
QueryStream.Write(ByteQuery, 0, ByteQuery.Length);
QueryStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding(1251));
string loginPage = sr.ReadToEnd();
sr.Close();
if (loginPage.IndexOf(@"div class=""error""") == -1)
{
httpWebResponse.Cookies = httpWebRequest.CookieContainer.GetCookies(httpWebRequest.RequestUri);
httpWebResponse.Close();
return cookies;
}
else
{
return null;
}
}
catch (Exception)
{
if (n < 3)
{
Thread.Sleep(400);
n++;
return GetCookies(url, login, password);
}
else
{
n = 0;
return null;
}
}
}
Костыльно-ориентированное велосипедирование. Выдержка из паттерна "тулза для работы с вебом", метод авторизации на какой-то из CMS.
+161
setInterval(
setTimeout(){
function(){
updater();
},
10
}
,2000);
Просто увидел в коде
+135
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main(){
FILE *filein, *fileout;
char fname1[15], fname2[15];
int n, m;
int i, j;
printf("Enter name of input file: "); scanf("%s", &fname1);
printf("Enter name of output file: "); scanf("%s", &fname2);
filein=fopen(fname1, "r");
fileout=fopen(fname2, "w");
if(filein==NULL){
fprintf(stderr, "\nError: can't open file \"%s\"\n\n", fname1);
fclose(filein);
fclose(fileout);
getch();
}
else{
fscanf(filein, "%d%d", &n, &m);
char ch[m][n];
int array[m][n];
int V[m][n];
for(i=0;i<m;i++){
for(j=0;j<n;j++){
V[i][j]=0;
}
}
for(i=0;i<m;i++){
for(j=0;j<n;j++){
fscanf(filein, "%s", &ch[i][j]);
if(ch[i][j]=='+') array[i][j]=1;
else if(ch[i][j]=='-') array[i][j]=0;
}
}
int sum;
for(i=0;i<m;i++){
sum=0;
for(j=0;j<n;j++){
sum+=array[i][j];
}
if(sum==1){
for(j=0;j<n;j++){
V[i][j]=array[i][j];
}
}
else continue;
}
int mm=0, c;
for(i=0;i<m;i++){
for(j=0;j<n;j++){
mm+=V[i][j];
}
}
c = m-mm;
int VoteArray[n];
for(j=0;j<n;j++){
sum=0;
for(i=0;i<m;i++){
sum+=V[i][j];
VoteArray[j]=sum;
}
}
float percent[n];
float per;
per = 100/(float)c;
for(i=0;i<n;i++){
if((percent[i]=per*VoteArray[i])>=7.0) fprintf(fileout, "%d ", i+1);
}
}
fclose(fileout);
fclose(filein);
puts("\nMission comleted\nPress any key...\n");
getch();
}
Фу, блять
+140
virtual QModelIndex parent(const QModelIndex &child) const = 0;
virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
int role = Qt::EditRole);
virtual QMap<int, QVariant> itemData(const QModelIndex &index) const;
virtual bool setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles);
virtual QStringList mimeTypes() const;
virtual QMimeData *mimeData(const QModelIndexList &indexes) const;
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent) const;
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent);
ну, вы поняли. они написали тысячи говнокода и говорят, что это круто.
они написали говно-пример, и говорят, что это круто.
а вы что думаете по этому поводу?
+57
bool operator ==( const CClass& lhs, const CClass& rhs )
{
bool rc = true;
// No self-comparison...
if ( &lhs != &rhs )
{
// Do not compare fields if result is already false...
if ( rc )
{
rc = ( lhs.frameId() == rhs.frameId());
}
if ( rc )
{
rc = ( lhs.objectId() == rhs.objectId());
}
if ( rc )
{
rc = ( lhs.type() == rhs.type() );
}
if ( rc )
{
rc = ( lhs.transition() == rhs.transition() );
}
if ( rc )
{
rc = ( lhs.rotation() == rhs.rotation() );
}
}
return rc;
}
+55
bool nt_utils::enum_processes(std::vector<uint32_t>& pids)
{
pids.clear();
PDWORD process_ids = NULL;
DWORD cb = ALLOC_SIZE;
DWORD bytes_returned = 0;
BOOL complete = FALSE;
__try {
while (!complete) {
process_ids = static_cast<PDWORD>(
::HeapAlloc(
::GetProcessHeap(),
HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
cb
)
);
if (::EnumProcesses(process_ids, cb, &bytes_returned)) {
if (cb == bytes_returned) {
::HeapFree(::GetProcessHeap(), 0, process_ids);
process_ids = NULL;
cb *= 2;
} else {
complete = TRUE;
}
} else {
::HeapFree(::GetProcessHeap(), 0, process_ids);
process_ids = NULL;
complete = TRUE;
}
}
if (process_ids) {
DWORD size = bytes_returned / sizeof(DWORD);
pids.reserve(size);
for (DWORD i = 0; i < size; ++i) {
assert(process_ids[i]);
pids[i] = process_ids[i];
}
::HeapFree(::GetProcessHeap(), 0, process_ids);
}
} __except (EXCEPTION_EXECUTE_HANDLER) {
if (process_ids) {
::HeapFree(::GetProcessHeap(), 0, process_ids);
}
return false;
}
return !!process_ids;
}
Получение id всех процессов
+152
function init() {
if (!document.body) return;
var body = document.body;
var html = document.documentElement;
// ...
}
// ...
https://gist.github.com/galambalazs/6477177/
Плавный скролл, я вот только не пойму, почему "if (!document.body) return;"?
Типа <body> тэга может не существовать?!
+156
for($i = 1; $i < $conf->nb_images + 1; $i++)
{
$ext_name = chr(ord('a')+$i-1);
?>
<label for="ad_picture<?php echo $i;?>"><?php echo ADSMANAGER_FORM_AD_PICTURE." ".$i; ?></label>
<input id="ad_picture<?php echo $i;?>" type="file" name="ad_picture<?php echo $i;?>" />
<?php
if ($isUpdateMode) {
$pic = $mosConfig_absolute_path."/images/$option/projects/".$ad_id.$ext_name."_t.jpg";
if ( file_exists( $pic)) {
echo "<img src='".$mosConfig_live_site."/images/$option/projects/".$ad_id.$ext_name."_t.jpg' align='top' border='0' alt='image$ad_id' />";
echo "<input type='checkbox' name='cb_image$i' value='delete' />".ADSMANAGER_AD_DELETE_IMAGE;
}
}
echo "<br />";
}
Угадайте что за CMS :)))
+57
if (!this) return;