- 1
- 2
- 3
- 4
$a = null;
var_dump($a, $a[0], $a); // NULL, NULL, NULL // what the fuck?
$a[0] = null;
var_dump($a); // array(0 => NULL)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+154
$a = null;
var_dump($a, $a[0], $a); // NULL, NULL, NULL // what the fuck?
$a[0] = null;
var_dump($a); // array(0 => NULL)
"PHP и type juggling", том третий. При этом на первый вызов $a[0] не ругается, будто при приведении NULL к пустому массиву в нем появляется нулевой элемент.
+154
class Session {
.....
public function getIdUser()
{
if ($this->isAnonymous()) {
return null;
}
return (int)$this->attributes[self::ATTR_ID_USER];
}
public function isAnonymous()
{
return empty($this->attributes[self::ATTR_ID_USER]);
}
....
}
............
$userId = $session->isAnonymous() ? null : (int)$session->getIdUser();
+154
class Registration{
protected $data;
protected $linc = "reg.php";
protected $v_log;
protected $query_login;
protected $v_pass;
protected $v_r_pass;
protected $v_pass_r_pass;
protected $v_mail;
public function __construct() {
$this->data = array('login'=> NULL, 'password'=> NULL, 'r_password'=> NULL, 'mail'=> NULL);
foreach($this->data as $key => $val) {
$this->data[$key] = $_POST[$key];
}
$this->v_log = $this->ver_login($this->data['login']);
$this->v_pass = $this->ver_pass($this->data['password']);
$this->v_r_pass = $this->ver_r_pass($this->data['r_password']);
$this->v_pass_r_pass = $this->ver_pass_r_pass($this->data['password'],$this->data['r_password']);
$this->v_mail = $this->ver_mail($this->data['mail']);
$this->error_reporting($this->v_log,$this->v_pass,$this->v_r_pass,$this->v_pass_r_pass,$this->v_mail, $this->error_log($this->linc));
}
protected function error_log($linc){
return("<p>В поле введены неверные данные!</p></br>"
. "<form action='$linc' metod='get'>"
. "<p>Вернуться и проверить<input type = 'submit' value = 'вернуться'></p>"
. "</form>");
}
protected function ver_login($login) {
if(empty($login) or (!preg_match("/^\A(\w){6,20}\Z/", $login))) {
$login = FALSE;
unset($login);
}else{
$login == TRUE;
$this->ver_db($login);
return($login);
}
}
protected function ver_db($log) {
$q = mysql_query("SELECT id FROM users WHERE login = '$log'");
$f = mysql_fetch_array($q);
if(empty($f['id']) or $f['id'] == '') {
return($log);
}else{
echo('Есть такой');
}
}
protected function ver_pass($pass) {
if(empty($pass) or (!preg_match("/^\A(\w){6,20}\Z/", $pass))) {
$pass == FALSE;
unset($pass);
}else {
$pass == TRUE;
$pass = md5($pass);
return($pass);
}
}
protected function ver_r_pass($r_pass) {
if(empty($r_pass) or (!preg_match("/^\A(\w){6,20}\Z/", $r_pass))) {
$r_pass == FALSE;
unset($r_pass);
}else {
$r_pass == TRUE;
$r_pass = md5($r_pass);
return($r_pass);
}
}
protected function ver_pass_r_pass($pass,$r_pass) {
if($pass != $r_pass) {
return(FALSE);
}else {
return (TRUE);
}
}
protected function ver_mail($mail) {
if(empty($mail) or (!preg_match("/^[a-zA-Z0-9_\.\-]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,6}$/", $mail))) {
$mail == FALSE;
unset($mail);
}else {
$mail == TRUE;
return($mail);
}
}
protected function reg_ins($log,$pass,$mail) {
$date = date("d.m.y");
$const = ACCES_KEY_DEFAULT;
$ins_query = "INSERT INTO users(login,password,mail,date,acces) VALUES ('$log','$pass','$mail','$date','$const')";
$insert = mysql_query($ins_query);
if(!$insert){
echo('error');
} else {
echo('ok');
}
}
protected function error_reporting($log,$pass,$r_pass,$pass_r_pass,$mail,$error) {
if($log == FALSE or $pass == FALSE or $r_pass == FALSE or $pass_r_pass == FALSE or $mail == FALSE){
echo($error);
} else {
//выполняем если все данные введены верно
$this->reg_ins($log, $pass, $mail);
}
:)
+53
long int p, q, n, t, flag, e[100], d[100], temp[100], m[100], en[100], j, i;
char msg[100];
long int cd(long int x)
{
long int k = 1;
while (1)
{
k = k + t;
if (k%x == 0)
return(k / x);
}
}
int prime(long int pr)
{
int i;
j = sqrtl(pr);
for (i = 2; i <= j; i++)
{
if (pr%i == 0)
return 0;
}
return 1;
}
void ce()
{
int k;
k = 0;
for (i = 2; i<t; i++)
{
if (t%i == 0)
continue;
flag = prime(i);
if (flag == 1 && i != p&&i != q)
{
e[k] = i;
flag = cd(e[k]);
if (flag>0)
{
d[k] = flag;
k++;
}
if (k == 99)
break;
}
}
}
void encrypt()
{
long int pt, ct, key = e[0], k, len;
i = 0;
len = strlen(msg);
while (i != len)
{
pt = m[i];
pt = pt - 96;
k = 1;
for (j = 0; j<key; j++)
{
k = k*pt;
k = k%n;
}
temp[i] = k;
ct = k + 96;
en[i] = ct;
i++;
}
en[i] = -1;
printf("\nTHE ENCRYPTED MESSAGE IS\n");
for (i = 0; en[i] != -1; i++)
printf("%c", en[i]);
}
трушные функции
+134
public static string GetString(string inpString, string defValue)
{
if (inpString == null)
return defValue;
return inpString;
}
Этот метод заботливо лижит в файле с всякими вспомогательными функциями, мало ли где может понадобиться
+135
public static byte[] ConvertStringToByteArray(string str)
{
int i, n;
n = str.Length;
byte[] x = new byte[n];
for (i = 0; i < n; i++)
{
x[i] = (byte)str[i];
}
return x;
}
Парни я не знаю баян это или нет, я лично не видел, но сторожилам виднее
+163
if (form.find('input[name*=payout_max]').val() > 0 || form.find('input[name*=payout_max]').val() > 0) {
form.find('input[name*=payout_max]').closest('div.form-group').show();
form.find('input[name*=payout_max]').closest('div.form-group').show();
} else {
form.find('input[name*=payout_max]').closest('div.form-group').hide();
form.find('input[name*=payout_max]').closest('div.form-group').hide();
}
код лида. видимо, два раза для пущей убедительности
+54
Exchange::Params pars = rawParams;
for(Exchange::Params::const_iterator i = rawParams.constBegin(); i!= rawParams.constEnd(); i++){
LOGN() << "Work with " << i.key() << "=" << i.value();
if(m_specific.contains(i.key())){
pars[i.key()] =
(this->*m_specific.value(i.key())) (i.value()); //черная магия :)
}
}
Наследие из большого рабочего проекта.
Чтобы сохранить ясность ума на весь день решил не пытаться понять что оно делает.
+133
body = Regex.Replace(Regex.Replace(x.SubTitle ?? "...", @"@\[", ""), @"\]\(([^:]+):(\d+)\)", "");
как индусы юзают регулярки
+152
jQuery(document).ready(function (){
var setCookie = function (c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
var getCookie = function (cname){
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++){
var c = ca[i].replace(/^\s+|\s+$/gm,'');
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
if (window.location.hash=='#stop' || (!getCookie('crimea_is_ukraine') && jQuery.inArray(codehelper_ip.Country,ciu_countries)>=0)){
if (typeof(_gaq)!='undefined'){
_gaq.push(['_trackEvent', 'Protest', 'Show', 'Crimea is Ukraine']);
}
http://putlerstop.2-you.info/share/stop_putler.js