- 1
return !!$this->db->where('id', $for_id)->update($for, $row);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+145
return !!$this->db->where('id', $for_id)->update($for, $row);
ояебал, у них наверное где-то склад с веществами
+165
function loadtitle($array) { //Функция установки meta-параметров в массив
$meta = array(); //Устанавливаем массив
$meta['title']=$array['title']; //Присваиваем метаданные
$meta['description'] = $array['description'];
$meta['author'] = $array['author'];
$meta['keywords'] = $array['keywords'];
return $meta; //Возвращаем массив метаданных
}
обнаружил в своем проекте 3 летней давности. сижу и тихо офигеваю)
+172
if(!empty($_SESSION["aktion"])){
//Если сесии не найдено то проверяем если куки
if(isset($_COOKIE["key"]) && isset($_COOKIE["PHPSESSID"]) && isset($_COOKIE["wrkesh"])){
//Прогоняем куки через фильтры
$test["key"] = htmlspecialchars($_COOKIE["key"]);
$test["key"] = stripslashes($_COOKIE["key"]);
$test["key"] = mysql_real_escape_string($_COOKIE["key"]);
$test["PHPSESSID"] = htmlspecialchars($_COOKIE["PHPSESSID"]);
$test["PHPSESSID"] = stripslashes($_COOKIE["PHPSESSID"]);
$test["PHPSESSID"] = mysql_real_escape_string($_COOKIE["PHPSESSID"]);
$test["wrkesh"] = htmlspecialchars($_COOKIE["wrkesh"]);
$test["wrkesh"] = stripslashes($_COOKIE["wrkesh"]);
$test["wrkesh"] = mysql_real_escape_string($_COOKIE["wrkesh"]);
//проверяем если такая запись в бд
$test_result = mysql_query("SELECT * FROM session WHERE md_5_id='$test[wrkesh]' AND ip='$_SERVER[REMOTE_ADDR]' AND clucc='$test[key]' AND sid='$test[PHPSESSID]'");
$test_myrow = mysql_fetch_array($test_result);
if($test_myrow ==true){
//Если даные с кук и бд совподают то создаём сессию
$_SESSION["aktive"] ="aktive";
mysql_close();
}
}
}
С "Ответов" mail.ru - типа проверка безопасности.
+94
function WindowProc(Wnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM ): LRESULT; stdcall;
type
Item = record
szItemNr: array[0..8] of char;
szItem: array[0..32] of char;
szItemDescription: array[0..32] of char;
end;
var
ListColumn: LV_COLUMN;
ListItem: LV_ITEM;
begin
// In case of Msg ...
case Msg of
WM_CREATE: // Create?
begin
// Create list
ListView := CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, '', WS_VISIBLE Or WS_CHILD Or LVS_REPORT Or LVS_SHOWSELALWAYS,
10, 10, 524, 300, Wnd, 0, hInstance, nil);
ListView_SetExtendedListViewStyle(ListView, LVS_EX_FULLROWSELECT Or LVS_EX_GRIDLINES);
// Filling list columns
with ListColumn do begin
mask := LVCF_FMT Or LVCF_WIDTH Or LVCF_TEXT Or LVCF_SUBITEM;
fmt := LVCFMT_LEFT;
iSubItem := 0;
cx := 200;
pszText := 'File name';
ListView_InsertColumn(ListView, 0, ListColumn);
iSubItem := 1;
cx := 250;
pszText := 'Folder path';
ListView_InsertColumn(ListView, 1, ListColumn);
iSubItem := 2;
cx := 70;
pszText := 'File size';
ListView_InsertColumn(ListView, 2, ListColumn);
end;
with ListItem do begin
mask := LVIF_TEXT;
iItem := 1;
iSubItem := 1;
pszText := PChar('test');
cchTextMax := SizeOf(PChar('test')) + 1;
end;
ListView_InsertItem(ListView, ListItem);
ListView_SetItemText(ListView, 1, 1, PChar('Hello world!'));
// Create static text, progress bar and buttons
StaticText := CreateWindowEx(0, 'Static', '', WS_CHILD Or WS_VISIBLE Or SS_CENTER,
10, 310, 524, 16, Wnd, ID_StaticText, hInstance, 0);
ProgressBar := CreateWindowEx(0, PROGRESS_CLASS, nil, WS_CHILD Or WS_VISIBLE Or PBS_SMOOTH,
9, 326, 525, 17, Wnd, ID_ProgressBar, hInstance, nil);
Button_Start := CreateWindowEx(WS_EX_STATICEDGE, 'Button', 'Start', BS_DEFPUSHBUTTON Or WS_VISIBLE Or WS_CHILD,
150, 350, 70, 25, Wnd, ID_Button_Start, hInstance, nil );
Button_Pause := CreateWindowEx(WS_EX_STATICEDGE, 'Button', 'Pause', WS_VISIBLE Or WS_CHILD Or WS_DISABLED,
230, 350, 70, 25, Wnd, ID_Button_Pause, hInstance, nil );
Button_Stop := CreateWindowEx(WS_EX_STATICEDGE, 'Button', 'Stop', WS_VISIBLE Or WS_CHILD Or WS_DISABLED,
310, 350, 70, 25, Wnd, ID_Button_Stop, hInstance, nil );
end;
WM_DESTROY: // Closing?
begin
PostQuitMessage(0);
Result := 0;
Exit; // Bye.
end;
WM_COMMAND: // Any command?
case LoWord(wParam) of
// ....................................
end;
end;
Пристрелите меня кто-нибудь. Или объясните, как работает этот волшебный listview %)
+67
package bytestring;
public class Main {
public static void main(String[] args) {
String source = new String("A ya sdelal etu hren s perevorotom stroki s ispolzovaniem bayta");
byte bytes[] = source.getBytes();
bytes = reverse(bytes);
String destination = new String(bytes);
System.out.println(destination);
}
private static void switchBytes(byte[] array, int a, int b) {
byte t = array[a];
array[a] = array[b];
array[b] = t;
}
public static byte[] reverse(byte[] bytes) {
int i, j;
int first, last;
int length = bytes.length;
//Переворачиваем всю строку
for(i = 0; i < length / 2; i++)
switchBytes(bytes, i, length - i - 1);
//Переворачиваем каждое слово строки
first = 0;
for(i = 1; i <= length; i++)
if(i == length || bytes[i] == ' ') {
last = i - 1;
for(j = first; j <= first + (last - first) / 2; j++)
switchBytes(bytes, j, first + last - j);
first = i + 1;
}
return bytes;
}
}
+147
int count(int a)
{
int cnt=0;
while(a)
{
++cnt;
}
return cnt;
}
Ф-ция для подсчета количества знаков числа. Взято с www.cyberforum.ru
+68
package bytestring;
public class Main {
public static void main(String[] args) {
String source = new String("A ya sdelal etu hren s perevorotom stroki s ispolzovaniem bayta");
byte bytes[] = source.getBytes();
////////////////////////////////////////////////////////////////////////
int i, j;
int length, first, last;
byte a;
length = bytes.length;
//Переворачиваем всю строку
for(i = 0; i < length / 2; i++) {
a = bytes[i];
bytes[i] = bytes[length - i - 1];
bytes[length - i - 1] = a;
}
//Переворачиваем каждое слово строки
first = 0;
for(i = 1; i <= length; i++)
if(i == length || bytes[i] == ' ') {
last = i - 1;
for(j = first; j <= first + (last - first) / 2; j++) {
a = bytes[j];
bytes[j] = bytes[first + last - j];
bytes[first + last - j] = a;
}
first = i + 1;
}
////////////////////////////////////////////////////////////////////////
char destination[] = new char[bytes.length];
for(i = 0; i < bytes.length; i++)
destination[i] = (char) bytes[i];
System.out.println(String.copyValueOf(destination));
}
}
+147
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#define N 5
#define TSK "durak"
using namespace std;
int m[N];
int main(void){
freopen(TSK".in", "rt", stdin);
freopen(TSK".out", "wt", stdout);
scanf("%d%d%d%d", &m[0], &m[1], &m[2], &m[3]);
sort(m, m + 4);
int ans(0);
for(int i = 1; i < 4; i++){
if(m[i] == m[i-1] && m[i] != 0)
ans++;
}
printf("%d\n", ans);
return 0;
}
+78
public static String toWritten(int i) {
return Integer.parseInt(String.valueOf(i).substring(String.valueOf(i).length()-1)) > 4 ?
"объектов" :
Integer.parseInt(String.valueOf(i).substring(String.valueOf(i).length()-1)) > 1 ?
"объекта" :
Integer.parseInt(String.valueOf(i).substring(String.valueOf(i).length()-1)) == 1 ?
"объект":
"объектов";
}
функция для вывода подобного:
1 объект
156 оъектов
итд.
+159
// TODO: use Virtual memory instead of heap!
#ifndef __CHUNK_H__
#define __CHUNK_H__
#include <windows.h>
#include "../JuceLibraryCode/JuceHeader.h"
class Chunk {
public:
enum CHUNK_DIRECTION {CHUNK_UNKNOWN = 0, CHUNK_IN, CHUNK_OUT};
Chunk (DWORD ChunkSize, WORD id, CHUNK_DIRECTION chunkDirection);
~Chunk ();
// override
virtual void eventChunkIsEmpty () {
Logger::outputDebugString(T("empty"));
}
virtual void eventChunkIsFull () {
Logger::outputDebugString(T("full"));
}
virtual void eventChunkOverrun () {
Logger::outputDebugString(T("overrun"));
}
DWORD getData (WORD *data, DWORD size) {
if (data == 0) return 0;
if (cs.tryEnter ()) { // if it's true, we locked.. (TODO: check, i'm not sure about that)
if (((size + nReadCounter) > nWriteCounter) || size == 0) { cs.exit(); return 0; }
memcpy (data, pBuffer + nReadCounter, size*sizeof(WORD));
nReadCounter += size;
if (nReadCounter == nWriteCounter) { eventChunkIsEmpty() ; nWriteCounter = 0; nReadCounter = 0; }
cs.exit ();
return size;
}
return 0;
}
DWORD putData (WORD *data, DWORD size) {
if (data == 0) return 0;
if (cs.tryEnter ()) { // if it's true, we locked.. (TODO: check, i'm not sure about that)
if ((size + nWriteCounter) > nSize) { eventChunkOverrun(); cs.exit (); return 0; }
memcpy (pBuffer + nWriteCounter, data, size*sizeof(WORD));
nWriteCounter += size;
if (nWriteCounter == nSize ) eventChunkIsFull();
cs.exit ();
return size;
}
return 0;
}
inline DWORD getSize () {
return nSize;
}
// TODO: add check for nWriteCounter?
inline bool setSize (DWORD ChunkSize) {
if (bExchangeIsActive) return false;
nSize = ChunkSize;
// TODO: add result check.
pBuffer = (WORD*) realloc ((void*)pBuffer, ChunkSize*sizeof(WORD));
if (pBuffer) return true;
return false;
}
inline DWORD getReadCounter () { return nReadCounter; }
inline DWORD getWriteCounter () { return nWriteCounter; }
juce_UseDebuggingNewOperator
protected:
bool bExchangeIsActive;
CHUNK_DIRECTION cdDirection;
DWORD nSize;
DWORD nWriteCounter;
DWORD nReadCounter;
WORD nChunkId;
WORD *pBuffer;
CriticalSection cs;
};
#endif
// EOF
#include "Chunk.h"
Chunk::Chunk (DWORD ChunkSize, WORD id, CHUNK_DIRECTION chunkDirection) {
bExchangeIsActive = false;
cdDirection = chunkDirection;
nSize = ChunkSize;
nWriteCounter = 0;
nReadCounter = 0;
nChunkId = id;
pBuffer = (WORD*) malloc (ChunkSize*sizeof(WORD));
zeromem (pBuffer, ChunkSize*sizeof(WORD));
}
Chunk::~Chunk () {
if (pBuffer) free (pBuffer);
}
// EOF
Посвящается всем изобретателям велосипедов и просто неудачникам.. :(