- 1
- 2
- 3
- 4
Руби говно на всей Земле
Руби говно другим во благо
Не за красивое "спасибо"
А за хорошее бабло
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
Руби говно на всей Земле
Руби говно другим во благо
Не за красивое "спасибо"
А за хорошее бабло
+3
N = int(input())
S = []
for i in range(N):
S.append(list(map(float, input().split())))
for i in range(len(S)):
S[i][0], S[i][1] = S[i][1], S[i][0]
S.sort()
for x in range(N):
for i in range(N-1):
if S[i][0] == S[i+1][0]:
if S[i][1] < S[i+1][1]:
S[i][1], S[i+1][1] = S[i+1][1], S[i][1]
for i in range(N):
print((str(round(S[i][1], 2))[:str(round(S[i][1], 2)).index('.')]+(str(round(S[i][1], 2))+'00000000')[str(round(S[i][1], 2)).index('.'):str(round(S[i][1], 2)).index('.')+3]),(str(round(S[i][0], 3))[:str(round(S[i][0], 3)).index('.')]+(str(round(S[i][0], 3))+'00000000')[str(round(S[i][0], 3)).index('.'):str(round(S[i][0], 3)).index('.')+4]))
Нужно было дописать эту прогу во что бы то ни стало...
+1
$parent = (new \yii\db\Query())
->select(['parent','parent_1','parent_2'])
->from('user')
->where(['id' => "$user_id",])
->all();
$sum_for_parent = (new \yii\db\Query())
->select(['first_parent'])
->from('referal_control')
->all();
$sum_for_parent = $sum_for_parent[0]['first_parent'];
$sum_for_parent_1 = (new \yii\db\Query())
->select(['second_parent'])
->from('referal_control')
->all();
$sum_for_parent_1 = $sum_for_parent_1[0]['second_parent'];
$sum_for_parent_2 = (new \yii\db\Query())
->select(['third_parent'])
->from('referal_control')
->all();
$sum_for_parent_2 = $sum_for_parent_2[0]['third_parent'];
Обращение к одной записи к 3-м полям через три запроса
−1
public function get_link(){
if (function(){
return stripos(strtolower($_SERVER['HTTP_USER_AGENT']), 'android');}){
return $this->get_android_link();
}
else{
return $this->get_ios_link();
}
}
+3
// https://github.com/julycoding/The-Art-Of-Programming-By-July/blob/master/ebook/code/c/1.1%EF%BC%9A%E5%B7%A6%E6%97%8B%E8%BD%AC%E5%AD%97%E7%AC%A6%E4%B8%B2.c
#include <stdio.h>
#include <string.h>
//字符串旋转问题,例如abcdef 左旋2位 变成 cdefab
//暴力移位法
void leftShift1(char * arr, int n)
{
size_t tmpLen = strlen(arr);
char tmpChar;
int i, j;
if (n >= 0)
{
for (i = 0; i < n; i++)
{
tmpChar = *arr;
for (j = 0; j < tmpLen - 1; j++)
{
*(arr + j) = *(arr + j + 1);
}
*(arr + tmpLen - 1) = tmpChar;
}
}
else
{
for (i = 0; i < -n; i++)
{
tmpChar = *(arr + tmpLen - 1);
for (j = tmpLen - 1; j > 0; j--)
{
*(arr + j) = *(arr + j - 1);
}
*arr = tmpChar;
}
}
}
Копаясь в гитхабе, нашел я тут The Art Of Programming By July, написанный каким-то китайцем.
https://github.com/julycoding/The-Art-Of-Programming-By-July
0
if($category_id!='')
$this->db->where('group_category =', $category_id);
if($group_by == TRUE)
$this->db->group_by('blog_cat_name');
У меня создалось впечатление, что здесь специально замаскировали все ифы. Чтобы читающий думал, что это линейный код. На скобках - экономят, на пробелах - экономят.
−1
internal static object CopyImmutableSortedDictionary<K, V>(object original, ICopyContext context)
{
return original;
}
Microsoft Orleans https://github.com/dotnet/orleans
Копирование объекта в 2к17
0
primary_list = tuple([line.strip() for line in open('file1.txt', 'r')])
secondary_list = tuple([line.strip() for line in open('file2.txt', 'r')])
f = open('test.txt', 'w')
users_unique = []
def isUnique(value):
if value not in users_unique:
users_unique.append(value)
return True
else:
return False
def common():
for item in primary_list:
if item is None:
continue
elif item in secondary_list and isUnique(item):
f.write(str(item)+'\r\n')
print 'Complete'
+4
function check_for_injection($_arr_check) {
$inj = 0;
foreach ($_arr_check as $n=>$v) {
$_text = "SELECT ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = " SELECT";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = "DELETE ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = "UPDATE ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = "INSERT ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = "LOAD ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = "DROP ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = "INTO ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = "OUTFILE ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
$_text = "CALL ";
if (strpos(strtoupper($v), $_text)!==false) $inj = 1;
}
return $inj;
}
$dd = check_for_injection($_REQUEST);
if ($dd==1) die();
Надежный способ проверки на взлом
0
#!/usr/bin/python
#encoding: utf-8
import sys
import time
import socket
import asyncore
import exceptions
from socket import AF_INET, SOCK_STREAM
from asyncore import dispatcher
from threading import Thread, RLock
class PiCalcThread(Thread):
def __init__(self, buffer, lock):
Thread.__init__(self)
self.buffer = buffer
self.lock = lock
def run(self):
""" See http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/spigot.pdf """
q,r,t,k,n,l = 1,0,1,1,3,3
while True:
if 4*q+r-t < n*t:
self.lock.acquire()
self.buffer.newDigits(str(n))
self.lock.release()
q,r,t,k,n,l = (10*q,10*(r-n*t),t,k,(10*(3*q+r))/t-10*n,l)
else:
q,r,t,k,n,l = (q*k,(2*q+r)*l,t*l,k+1,(q*(7*k+2)+r*l)/(t*l),l+2)
time.sleep(0.001)
class PiGenerator(list):
def __init__(self):
list.__init__(self)
self.calculator = None
self.lock = RLock()
self.digits = ''
def subscribe(self, obj):
self.lock.acquire()
try:
self.append(obj)
self._notify(obj=obj)
finally:
self.lock.release()
if not self.calculator:
self.calculator = PiCalcThread(self, self.lock)
self.calculator.start()
else:
if len(self) > 0:
self._resumeCalculator()
def unsubscribe(self, obj):
self.lock.acquire()
self.remove(obj)
self.lock.release()
if len(self) <= 0:
self._pauseCalulator()
def _pauseCalulator(self):
self.lock.acquire()
def _resumeCalculator(self):
try: self.lock.release()
except exceptions.AssertionError: pass
def _notify(self, digits = None, obj = None):
objs = [obj] if obj else self
digits = digits or self.digits
for obj in objs:
obj.update(digits)
def newDigits(self, digits):
self.digits += digits
self._notify(digits)