- 1
var now = DateTimeOffset.Now.AddHours(-1);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
var now = DateTimeOffset.Now.AddHours(-1);
Почти сейчас.
0
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Gitis implements ActionListener{
JFrame frame;
public static void main(String[] args) {
Gitis gitis = new Gitis();
gitis.go();
}
public void go(){
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Next Color");
button.addActionListener(this);
MyDrawPanel panel = new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, panel);
frame.setSize(500, 500);
frame.setVisible(true);
frame.setTitle("Paint Oval");
}
public void actionPerformed(ActionEvent event){
frame.repaint();
}
}
class MyDrawPanel extends JPanel{
public void paintComponent(Graphics g){
g.fillRect(0, 0, this.getWidth(),this.getHeight());
int one = (int) (Math.random() * 255);
int two = (int) (Math.random() * 255);
int three = (int) (Math.random() * 255);
Color color = new Color(one, two, three);
g.setColor(color);
g.fillOval(40, 70 , 50, 50);
}
}
Смена цвета окружности по нажатию кнопки, Оцените код!
0
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ServakPro;
/**
*
* @author bb
*/
import Debugger.NetDebugger;
import Debugger.NetDebuggingInter;
import Servak.Db.Experimental.SettingsBandit;
import java.io.*;
import java.net.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class Server extends Object implements NetDebuggingInter {
static final int INITIALWORKERTHREADS = 20;// tune this!
static final int port = SettingsBandit.SERVER_PORT;
BlockingQueue<Socket> queue;
private ServerSocket ss;
private Thread internalThread;
private volatile boolean noStopRequested;
private NetDebugger netDebugger = new NetDebugger();
private void init() {
for (int i = 0; i < INITIALWORKERTHREADS; i++) {
new Thread(new MultiSessionTask(ss, queue)).start();
}
}
public Server(BlockingQueue<Socket> q) throws IOException {
ss = new ServerSocket(port);
noStopRequested = true;
this.queue = q;
this.init();
Runnable r = new Runnable() {
public void run() {
try {
runWorkFast();
} catch (Exception x) {
netDebugger.fireServerFaultEvent("SERVER: there is exception: ", x);
x.printStackTrace();
}
}
};
internalThread = new Thread(r);
internalThread.setName("My server Thread");
internalThread.start();
}
private void runWorkFast() {
for (;;) {
try {
Socket sock = ss.accept();
int thr = MultiSessionTask.waitCount();
if (thr > 0) {
queue.add(sock);
} else {
queue.add(sock);
new Thread(new DynamicMultiSessionTask(ss, queue)).start();
}
} catch (IOException exc) {
exc.printStackTrace();
}
if (ss.isClosed()) {
break; // for (;;)
}
} // catch
}
public synchronized void stopRequest() {
noStopRequested = false;
//internalThread.interrupt();
if (ss != null) {
try {
ss.close();
} catch (IOException x) {
// ignore
} finally {
ss = null;
}
}
}
public boolean isAlive() {
return internalThread.isAlive();
}
public static void main(String[] args) {
try {
BlockingQueue<Socket> bq = new ArrayBlockingQueue<>(40);
Server serv = new Server(bq);
} catch (IOException ex) {
Мега-сервер
https://wasm.in/threads/skorost-obrabotki-klientov-v-servere-na-dzhava.32423/#post-395115
−3
https://habrahabr.ru/company/mailru/blog/344696/
Долбоёбы из "Mail.Ru", приобрётшие авторитет только благодаря тому, что их сайтик случайно стал одним из самых популярных, учат жизни:
>>> НЕ ДЕЛАЙТЕ ТАК:
>>>
>>> /* Небезопасный код: */
>>> $query = $pdo->query("SELECT * FROM users WHERE username = '" . $_GET['username'] . "'");
>>>
>>> Делайте так:
>>>
>>> /* Защищено от SQL-внедрений: */
>>> $results = $easydb->row("SELECT * FROM users WHERE username = ?", $_GET['username']);
Будто переменную в первом варианте запроса нельзя пропустить через "mysql_real_escape_string" или иную экранирующую функцию.
Зато в итоге запрос остаётся очевидным, без даунских высчитываний вида "каким по счёту является значение поля и какой по счёту вопросительный знак ему соответствует". Тьфу, блядь...
+3
#!/bin/sh
while true; do
date "+Time is %H %M. Stop lurking and get the fuck to work" | say
sleep 1800
done
Я наконец нашёл применение встроенному в OS X TTS-движку.
0
http://shitcode.net/
У говнокода появился конкурент
0
Хуй, пизда, противогаз,
Конь, бобёр и дикобраз.
0
import java.awt.event.*;
import javax.swing.*;
public class Experiment implements ActionListener{
JFrame frame;
JButton button;
public static void main(String[] args) {
Experiment experiment = new Experiment();
experiment.go();
}
public void go(){
frame = new JFrame();
button = new JButton("You is winner!");
button.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(button);
frame.setSize(400, 400);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event){
button.setText("You is loser!");
frame.setSize(700, 700);
}
}
GUI, Создание кнопки и ее изменение, а также изменение фрейма!!! ОЦЕНИТЕ КОД!
+1
function TL($a)
{
$tkk = explode('.', TKK());
$b = $tkk[0];
for($d = array(), $e = 0, $f = 0; $f < mb_strlen ( $a, 'UTF-8' ); $f ++) {
$g = charCodeAt ( $a, $f );
if (128 > $g) {
$d [$e ++] = $g;
} else {
if (2048 > $g) {
$d [$e ++] = $g >> 6 | 192;
} else {
if (55296 == ($g & 64512) && $f + 1 < mb_strlen ( $a, 'UTF-8' ) && 56320 == (charCodeAt ( $a, $f + 1 ) & 64512)) {
$g = 65536 + (($g & 1023) << 10) + (charCodeAt ( $a, ++ $f ) & 1023);
$d [$e ++] = $g >> 18 | 240;
$d [$e ++] = $g >> 12 & 63 | 128;
} else {
$d [$e ++] = $g >> 12 | 224;
$d [$e ++] = $g >> 6 & 63 | 128;
}
}
$d [$e ++] = $g & 63 | 128;
}
}
$a = $b;
for($e = 0; $e < count ( $d ); $e ++) {
$a += $d [$e];
$a = RL ( $a, '+-a^+6' );
}
$a = RL ( $a, "+-3^+b+-f" );
$a ^= $tkk[1];
if (0 > $a) {
$a = ($a & 2147483647) + 2147483648;
}
$a = fmod ( $a, pow ( 10, 6 ) );
return $a . "." . ($a ^ $b);
}
function translate($sl, $tl, $q)
{
$tk = TL($q);
$q = urlencode(stripslashes($q));
$url = "https://translate.google.com/translate_a/t?client=webapp&sl=".$sl."&tl=".$tl."&hl=".$tl."&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=2&ssel=0&tsel=0&kc=1&tk=". $tk ."&q=" . $q;
$output = json_decode(file_get_contents($url));
return str_replace('"', '', $output);
}
Локализация из одного индусского проекта за 50$
0
import tkinter
import random
# constants
WIDTH = 540
HEIGHT = 480
BG_COLOR = 'white'
MAIN_BALL_COLOR = 'blue'
MAIN_BALL_RADIUS = 25
COLORS = ['aqua', 'fuchsia', 'pink', 'yellow', 'gold', 'chartreuse']
NUM_OF_BALLS = 9
MAX_RADIUS = 35
MIN_RADIUS = 15
DELAY = 8
INIT_DX = 1
INIT_DY = 1
ZERO = 0
# ball class
class Ball():
def __init__(self, x, y, r, color, dx=0, dy=0):
self.x = x
self.y = y
self.r = r
self.color = color
self.dx = dx
self.dy = dy
def draw(self):
canvas.create_oval(self.x - self.r, self.y - self.r, self.x + self.r, self.y + self.r, fill=self.color,
outline=self.color)
def hide(self):
canvas.create_oval(self.x - self.r, self.y - self.r, self.x + self.r, self.y + self.r, fill=BG_COLOR,
outline=BG_COLOR)
def is_collision(self, ball):
a = abs(self.x + self.dx - ball.x)
b = abs(self.y + self.dy - ball.y)
return (a * a + b * b) ** 0.5 <= self.r + ball.r
def move(self):
# collision with the walls
if (self.x + self.r + self.dx >= WIDTH) or (self.x - self.r + self.dx <= ZERO):
self.dx = -self.dx
if (self.y + self.r + self.dy >= HEIGHT) or (self.y - self.r + self.dy <= ZERO):
self.dy = -self.dy
self.hide()
self.x += self.dx
self.y += self.dy
if self.dx * self.dy != 0:
self.draw()
# process the mouse events
def mouse_click(event):
global main_ball
if event.num == 1: # left mouse button
if 'main_ball' not in globals(): # старт
main_ball = Ball(event.x, event.y, MAIN_BALL_RADIUS, MAIN_BALL_COLOR, INIT_DX, INIT_DY)
if main_ball.x > WIDTH / 2:
main_ball.dx = -main_ball.dx
if main_ball.y > HEIGHT / 2:
main_ball.dy = -main_ball.dy
main_ball.draw()
# create a list of objects-balls
def create_list_of_balls(number):
lst = []
return lst
# games main loop
def main():
if 'main_ball' in globals():
main_ball.move()
root.after(DELAY, main)
# create a window, the canvas and start game
root = tkinter.Tk()
root.title("Colliding Balls")
canvas = tkinter.Canvas(root, width=WIDTH, height=HEIGHT, bg=BG_COLOR)
canvas.pack()
canvas.bind('<Button-1>', mouse_click)
canvas.bind('<Button-2>', mouse_click, '+')
canvas.bind('<Button-3>', mouse_click, '+')
balls = create_list_of_balls(NUM_OF_BALLS)
if 'main_ball' in globals(): # for restarts
del main_ball
main()
root.mainloop()