- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
(function() {
(function init() {
document.addEventListener("DOMContentLoaded", DOMContentLoaded, false);
})();
})();
function DOMContentLoaded() {
//...
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+157
(function() {
(function init() {
document.addEventListener("DOMContentLoaded", DOMContentLoaded, false);
})();
})();
function DOMContentLoaded() {
//...
}
И да, jQuery подключена на странице.
−163
public function algorithmChanged(arg1:flash.events.Event):*
{
var loc1:*;
loc1 = null;
if (currentAlgorithm != null)
removeChild(currentAlgorithm);
loc1 = arg1.target.selectedLabel;
currentAlgorithm = null;
animationManager.resetAll();
if (loc1 != "Heap")
if (loc1 != "Comparison Sort")
if (loc1 != "Counting Sort")
if (loc1 != "Bucket Sort")
if (loc1 != "Radix Sort")
if (loc1 != "Heap Sort")
if (loc1 != "Binary Search Tree")
if (loc1 != "AVL Tree")
if (loc1 != "Open Hashing")
if (loc1 != "Closed Hashing")
if (loc1 != "Graph")
if (loc1 != "DFS")
if (loc1 != "BFS")
if (loc1 != "Connected Components")
if (loc1 != "Dijkstra")
if (loc1 != "Prim")
if (loc1 != "Kruskal")
if (loc1 != "Topological Sort")
if (loc1 != "Floyd-Warshall")
if (loc1 != "B Tree")
if (loc1 != "Binomial Queue")
if (loc1 != "Disjoint Sets")
if (loc1 != "Array Stack")
if (loc1 != "Array Queue")
if (loc1 != "Linked List Stack")
if (loc1 != "Linked List Queue")
if (loc1 != "Red Black Tree")
if (loc1 != "Closed Hashing (buckets)")
if (loc1 == "B+ Tree")
{
currentAlgorithm = new BPlusTree(animationManager);
addChildAt(currentAlgorithm, 0);
}
else
{
currentAlgorithm = new ClosedHash2(animationManager);
addChildAt(currentAlgorithm, 0);
}
else
{
currentAlgorithm = new RedBlackTree(animationManager);
addChildAt(currentAlgorithm, 0);
}
и т.д. пока не закроются все if'ы
Визуализатор сортировок университета Сан-Франциско
+127
//top edge
if (normal)
for (int i = y; i > 0; i--)
if (_map[x, i] == 0)
if ((i - 1) > minDist) { mnt.Corners[0] = new Point(x, i - 1 + minDist); break; }
else { normal = false; mnt.Height = -1; }
//top-right edge
if (normal)
for (int i = 0; ((x + i) < MAP_SIZE) & ((y - i) > 0); i++)
if (_map[x + i, y - i] == 0)
if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[1] = new Point(x + i - 1 - minDist, y - i + 1 + minDist); break; }
else { normal = false; mnt.Height = -1; }
//right edge
if (normal)
for (int i = x; i < MAP_SIZE; i++)
if (_map[i, y] == 0)
if ((MAP_SIZE - i - 1) > minDist) { mnt.Corners[2] = new Point(i - 1 - minDist, y); break; }
else { normal = false; mnt.Height = -1; }
//bottom-right edge
if (normal)
for (int i = 0; ((x + i) < MAP_SIZE) & ((y + i) < MAP_SIZE); i++)
if (_map[x + i, y + i] == 0)
if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[3] = new Point(x + i - 1 - minDist, y + i - 1 - minDist); break; }
else { normal = false; mnt.Height = -1; }
//bottom edge
if (normal)
for (int i = y; i > 0; i++)
if (_map[x, i] == 0)
if ((i - 1) > minDist) { mnt.Corners[4] = new Point(x, i - 1 - minDist); break; }
else { normal = false; mnt.Height = -1; }
//bottom-left edge
if (normal)
for (int i = 0; ((x - i) < MAP_SIZE) & ((y + i) > 0); i++)
if (_map[x - i, y + i] == 0)
if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[5] = new Point(x - i + 1 + minDist, y + i - 1 - minDist); break; }
else { normal = false; mnt.Height = -1; }
//left edge
if (normal)
for (int i = x; i > 0; i--)
if (_map[i, y] == 0)
if ((i + 1) > minDist) { mnt.Corners[6] = new Point(i + 1 + minDist, y); break; }
else { normal = false; mnt.Height = -1; }
//top-left edge
if (normal)
for (int i = 0; ((x - i) > 0) & ((y - i) > 0); i++)
if (_map[x - i, y - i] == 0)
if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[7] = new Point(x - i + 1 + minDist, y - i + 1 + minDist); break; }
else { normal = false; mnt.Height = -1; }
Мне было лень думать. Очень лень.
+132
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
void usage(char *progname)
{
fprintf(stderr,"Usage: %s [-i <interval>]\n",progname);
exit(1);
}
int main(int argc, char *argv[])
{
int arg;
size_t alloc = 1000;
uid_t userid = getuid();
while ((arg = getopt(argc,argv,"")) != -1) {
switch(arg) {
default:
usage(argv[0]);
break;
}
}
//const char *basecmd = "sudo turbostat -s -i 1 2>&1";
char ghz[8];
char *junkbuffer = malloc(sizeof(char)*1000);
const char *basecmd = "turbostat -s -i 1 2>&1";
seteuid(0);
setuid(0);
FILE *turboPipe = popen(basecmd,"r");
seteuid(userid);
setuid(userid);
/* ignore first line */
getline(&junkbuffer,&alloc,turboPipe);
fscanf(turboPipe,"%*s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n",ghz);
free(junkbuffer);
fprintf(stdout,"%s\n",ghz);
pclose(turboPipe);
return 0;
}
Установил новый Debian на ноут. Искал инфу по Intel TurboBoost.
Наткунлся на это
http://technicallyliving.blogspot.com/2012/06/intel-turboboost-and-linux.html
Улыбнул вайл-свитч. Что мешало автору обойтись без свитча?
+79
package testapp;
public class TestApp {
public static void main(String[] args) {
int count = 0;
for (int i = 0; i < 1000000; i++) {
if (isLucky(i)) {
System.out.println(i);
count++;
}
}
System.out.println("Total: " + count);
}
static boolean isLucky(final int n) {
String num = Integer.toString(n);
switch(6 - num.length()) {
case 1:
num = "0".concat(num);
break;
case 2:
num = "00".concat(num);
break;
case 3:
num = "000".concat(num);
break;
case 4:
num = "0000".concat(num);
break;
case 5:
num = "00000".concat(num);
break;
}
return (((getDigitAt(num, 0) + getDigitAt(num, 1) == getDigitAt(num, 2) + getDigitAt(num, 3))) & ((getDigitAt(num, 2) + getDigitAt(num, 3) == getDigitAt(num, 4) + getDigitAt(num, 5))));
}
static int getDigitAt(String number, int index) {
return Character.getNumericValue(number.charAt(index));
}
}
Моё. Проверяет числа на "счастливость". Число счастливое, если в 6-значном числе сумма каждой пары соседних цифр одинакова. Т.е 211221 - счастливое, т.к. (2+1) = (1+2) = (2+1)
+89
public void render(){
for(int y = 0; y < height; y++){
if(y < 0 || y >= height) break;
for(int x = 0; x < width; x++){
if(x < 0 || x >= width) break;
int tileIndex = (x >> 4) + (y >> 4) * 64;
pixels[x + y * width] = tiles[tileIndex];
}
}
}
чтоб уж наверняка
http://www.youtube.com/watch?v=uPkXZmOuqGI
−103
sub exdef {
my ($hash, $key) = @_;
if (exists $hash->{$key} && defined $hash->{$key}) {
return 1;
}
return 0;
}
No comments.
BTW.
http://perldoc.perl.org/functions/exists.html
http://perldoc.perl.org/functions/defined.html
+16
try
{
Application->Initialize();
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
Найдено в проекте написанном на Borland C++Builder :)
+103
if (s[n][c]='1')and(s[n][c+1]='0')and(s[n+1][c]='0')and(n=1)and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n][c-1]='0')and(s[n+1][c]='0')and(s[n][c+1]='0')and(n=1) then writeln('*');
if (s[n][c]='1')and(s[n][c-1]='0')and(s[n+1][c]='0')and(n=1)and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n-1][c]='0')and(s[n][c-1]='0')and(s[n+1][c]='0')and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n-1][c]='0')and(s[n][c-1]='0')and(n=10)and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='0')and(s[n-1][c]='0')and(s[n][c-1]='0')and(n=10) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='0')and(s[n-1][c]='0')and(n=10)and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n+1][c]='0')and(s[n][c+1]='0')and(s[n-1][c]='0')and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='.')and(s[n+1][c]='.')and(n=1)and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n][c-1]='.')and(s[n+1][c]='.')and(s[n][c+1]='.')and(n=1) then writeln('*');
if (s[n][c]='1')and(s[n][c-1]='.')and(s[n+1][c]='.')and(n=1)and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n-1][c]='.')and(s[n][c-1]='.')and(s[n+1][c]='.')and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n-1][c]='.')and(s[n][c-1]='.')and(n=10)and(c=10) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='.')and(s[n-1][c]='.')and(s[n][c-1]='.')and(n=10) then writeln('*');
if (s[n][c]='1')and(s[n][c+1]='.')and(s[n-1][c]='.')and(n=10)and(c=1) then writeln('*');
if (s[n][c]='1')and(s[n+1][c]='.')and(s[n][c+1]='.')and(s[n-1][c]='.')and(c=1) then writeln('*');
Конец решения первой задачи все из той же дистанционки.
На этот раз мопед не мой, а одной юной дамы.
Вот за ЭТО я и недолюбливаю Паскаль: иногда код хер прочитаешь. А еще путаница с типами. И логикой. Гы.
+155
$content="{$_POST["From"]} - {$_POST["To"]}: {$_POST["DepartureDate"]},{$_POST["ArrivalDate"]}; {$_POST["date_type"]}";
$content=str_replace("'","",$content);
if(!mysql_num_rows(mysql_query("select id from table where sess_id='$sess_id' AND aff_id='$aff_id' AND operation_id='$operation_id' AND `content`='$content'"))>0){
}