- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
#!/bin/bash
c=0
d=0
while :
do
c=0
while let "c<=10"
do
let c++
echo -n $d/$c
echo
done
echo
let d++
let "d=d%10"
done
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−133
#!/bin/bash
c=0
d=0
while :
do
c=0
while let "c<=10"
do
let c++
echo -n $d/$c
echo
done
echo
let d++
let "d=d%10"
done
Не помню уже что
−135
#!/bin/bash
touch pp.sh
chmod 777 pp.sh
echo "#!/bin/bash" > ./pp.sh
while :
do
read x
n=`cat ~/.bash_history | wc -l`
let c=${RANDOM:0:3}
cat -b ~/.bash_history | grep ${RANDOM:0:3} | gawk '{ print $2" "$3" "$4" "$6" "$7 }' >> pp.sh
cat -b ~/.bash_history | grep ${RANDOM:0:3} | gawk '{ print $2" "$3" "$4" "$6" "$7 }'
done
Рандом
−140
#!/bin/bash
x=0;
y=0;
clear;
while :
do
while let "x>0"
do
let y++
let x--
clear;
tput cup $x $y
echo "+"
sleep 0.1s;
done
let y++;
echo $y" "$x
x=0;
while let "y>0"
do
let y--
let x++
clear;
tput cup $x $y
echo "+"
sleep 0.1s;
done
done
Обход курсора зигзагом
−137
#!/bin/bash
x=0;
y=0;
while :
do
for((iy=0;iy<=25;iy++))
{
for((i=0;i<=190;i++))
{
let y++;
clear
tput cup $x $y
echo "+";
sleep 0.01s;
}
let x++;
for((i=0;i<=190;i++))
{
let y--;
clear
tput cup $x $y
echo "+";
sleep 0.01s;
}
let x++;
}
for((iy=0;iy<=25;iy++))
{
for((i=0;i<=190;i++))
{
let y++;
clear
tput cup $x $y
echo "+";
sleep 0.01s;
}
let x--;
for((i=0;i<=190;i++))
{
let y--;
clear
tput cup $x $y
echo "+";
sleep 0.01s;
}
let x--;
}
done
Обход курсора
−141
#!/bin/bash
read str
str=${str//1/2}
str=${str//0/1}
str=${str//2/0}
echo $str
str=${str##*0};
echo $str
exit 0
for pid in `ps -ef | gawk '{ print $2 }'`
do
echo "pid "$pid;
cat /proc/$pid/comm
cmd=`cat /proc/$pid/cmdline`
echo ''
for fdinfo in `ls /proc/$pid/fd`
do
echo " "$fdinfo
if [ $USER==root ]; then
fd=`ls -l /proc/$pid/fd/$fdinfo | gawk '{ print $11 }'`
else
fd=`ls -l /proc/$pid/fd/$fdinfo | gawk '{ print $10 }'`
fi
owner=`ls -l $fd | gawk '{ print $3}'`
echo " "$fd" pid"$pid" cmdline "$cmd" own "$owner
done
done
Ищет файлы процесов
−138
#!/bin/bash
function create_file
{
for fl in `cat $1`
do
$2 $fl
echo "$1 "$fl
done
}
function tar_file
{
$2 `cat $1`
}
create_file ~/fl.txt touch
create_file ~/rl.txt rm
create_file ~/dl.txt mkdir
tar_file ~/tl.txt "tar -cjvf pt.tar.bz2"
exit 0
Создаёт и удаляет файлы и директории
−90
#! /usr/bin/python2.4
# -*- coding: utf-8 -*-
'''
from Tkinter import *
import subprocess
import Queue
import threading
class ifStatThreadClass(threading.Thread):
"""класс потока с ifstat"""
def __init__(self,breakCount):
global listBox
selectedIface=listBox.curselection()
if not selectedIface: selectedIface=0
self.ifaceName=listBox.get(selectedIface);
self.breakCount=breakCount
threading.Thread.__init__(self)
def run(self):
global queue
global stop_event
# рабочий тред, запускает ifstat на вывод 20 строк
global listBox
cmd="ifstat -i %s 1 %s"% (self.ifaceName, self.breakCount,)
print "Запускаю: %s"%cmd
PIPE = subprocess.PIPE
p = subprocess.Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,
stderr=subprocess.STDOUT, close_fds=True)
#пока нет стоп-события ловим строки из стдоута
if (stop_event.is_set()): print "stop event detected!"
while not stop_event.is_set():
s = p.stdout.readline()
if not s: break
if self.breakCount==0: break
self.breakCount-=1
#кладем очередную строку в очередь
queue.put(s)
print s,
def startIfStat():
""" стартуем рабочий тред"""
global stop_event
global ifStatThread
ifStatThread = ifStatThreadClass(10)
try:
stop_event.clear()
ifStatThread.start()
except:
print "Не могу запустить поток! Может, он уже запущен?"
stop_event.set()
#вот тут стартуем
def stopWorker():
"""создаем стоп-событие"""
print("Тпырррр!")
global stop_event
global ifStatThread
# установим событие останова
stop_event.set()
def ifStatResultUpdater():
"""обновлялка текстового поля из очереди query"""
global queue
global stop_event
global ifStatResult
global ifStatThread
global emptyQueueCounter
# print("updater")
# ifStatResult.configure(text=time.strftime('%H:%M:%S'))
#только если не было стоп-события
if not stop_event.is_set():
if ifStatThread.isAlive(): print "Поток еще жив!"
else: print "Потока в живых не обнаружено"
s=''
try:
#берем из очереди строку и выводим на лейбл
print 'Что у нас в очереди? ',
s = queue.get_nowait()
print "а в очереди вот:",s
ifStatResult.configure(text=s)
except Queue.Empty:
print('ничего в очереди нету(')
if (emptyQueueCounter>2):
print('аааа.. похоже, все умерли... щас заново запущу!')
startIfStat()
emptyQueueCounter=0
emptyQueueCounter+=1
#если стоп-события не было, запускаем эту же функцию через секунду
root.after(1000,ifStatResultUpdater)
queue = Queue.Queue() #создаем очередь
emptyQueueCounter=0
Мой первый (мало-мальÑки Ñерьезный) опыт на питоне. Выводит ÑпиÑок из 3Ñ… интерфейÑов, по нажатию Старт запуÑкает тред Ñ Ð¸Ñ„Ñтатом, выводит в окошко результаты. Кривинько-коÑо, но работает)
ЕÑли еÑть Ð·Ð°Ð¼ÐµÑ‡Ð°Ð½Ð¸Ñ ÐºÐ°Ðº криво напиÑано и Ð¿Ñ€ÐµÐ´Ð»Ð¾Ð¶ÐµÐ½Ð¸Ñ ÐºÐ°Ðº лучше, жду комментарии.
P.S. до Ñтого пиÑал на пхÐ%BF, D1‚ак что не пинайте Ñильно)
+145
System.out.println("ERROR: Second call to constructor of static parser. You must");
System.out.println(" either use ReInit() or set the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
c2java.zip (с 2 java конвертор)
код старый и декомпилированный, но декомпилятор тут ни при чем = )
+162
<?php
$month_cols = array("january" => 31,
"february" => 28,
"march" => 31,
"april" => 30,
"may" => 31,
"june" => 30,
"july" => 31,
"august" => 31,
"september" => 30,
"october" => 31,
"november" => 30,
"december" => 31);
if($_POST["month_to_change"])
{
$month_to = $_POST["month_to_change"];
for($i = 1; $i <= $month_cols[$_POST["month_to_change"]]; $i++)
{
$description = mysql_real_escape_string($_POST["textar_".$i]);
mysql_query("UPDATE `calender` SET `description` = '$description' WHERE `day` = '$i' AND `month` = '$month_to' LIMIT 1");
}
}
echo "<h3>Лунный календарь</h3>";
if($_POST["month_change"])
{
if($_POST["month"] == "january") $jan_sel = "selected";
if($_POST["month"] == "february") $feb_sel = "selected";
if($_POST["month"] == "march") $mar_sel = "selected";
if($_POST["month"] == "april") $apr_sel = "selected";
if($_POST["month"] == "may") $may_sel = "selected";
if($_POST["month"] == "june") $jun_sel = "selected";
if($_POST["month"] == "july") $jul_sel = "selected";
if($_POST["month"] == "august") $aug_sel = "selected";
if($_POST["month"] == "september") $sep_sel = "selected";
if($_POST["month"] == "october") $oct_sel = "selected";
if($_POST["month"] == "november") $nov_sel = "selected";
if($_POST["month"] == "december") $dec_sel = "selected";
}
else
{
$jan_sel = "selected";
}
$changing_month = $_POST["month"];
if($changing_month == "") $changing_month = "january";
echo "<table>\n";
echo "<tr><td>\n";
echo "<form name=\"form_name\" id=\"form_id\" action=\"\" method=\"post\">\n";
echo "<select name=\"month\" onChange=\"this.form.submit()\">\n
<option value=\"january\" $jan_sel>Январь</option>\n
<option value=\"february\" $feb_sel>Февраль</option>\n
<option value=\"march\" $mar_sel>Март</option>\n
<option value=\"april\" $apr_sel>Апрель</option>\n
<option value=\"may\" $may_sel>Май</option>\n
<option value=\"june\" $jun_sel>Июнь</option>\n
<option value=\"july\" $jul_sel>Июль</option>\n
<option value=\"august\" $aug_sel>Август</option>\n
<option value=\"september\" $sep_sel>Сентябрь</option>\n
<option value=\"october\" $oct_sel>Октябрь</option>\n
<option value=\"november\" $nov_sel>Ноябрь</option>\n
<option value=\"december\" $dec_sel>Декабрь</option>\n
</select>\n";
echo "<input type=\"hidden\" name=\"month_change\" value=\"change\">\n";
echo "</td></tr>\n";
for($i = 1; $i <= $month_cols[$changing_month]; $i++)
{
$q_q2 = mysql_query("SELECT `description` FROM `calender` WHERE `day` = '$i' AND `month` = '$changing_month' LIMIT 1");
$descr = mysql_fetch_row($q_q2);
echo "<tr valign=\"top\" cols=\"5\">
<td><b>$i</b></td>
<td>
<textarea name=\"textar_$i\">".$descr[0]."</textarea>
</td>
</tr>\n";
}
echo "<tr>
<td colspan=\"2\" align=\"right\">
<input type=\"submit\" value=\"Сохранить\">
</td>
</tr>\n";
echo "<input type=\"hidden\" name=\"month_to_change\" value=\"$changing_month\">\n";
echo "</form>";
echo "</table>";
?>
А это уже часть, которая апдейтит базу :-)
+159
<?php
$ident = mysql_connect("localhost", "root", "");
mysql_select_db("database");
$month_cols = array("january" => 31,
"february" => 28,
"march" => 31,
"april" => 30,
"may" => 31,
"june" => 30,
"july" => 31,
"august" => 31,
"september" => 30,
"october" => 31,
"november" => 30,
"december" => 31);
foreach($month_cols as $key => $value)
{
for($i = 1; $i <= $value; $i++)
{
mysql_query("INSERT INTO `calender` SET `day` = '$i', `month` = '$key'");
}
}
mysql_close($ident);
?>
Недавнее творение.
Нужно было создать базу данных, которая потом будет апдейтиться.