+119
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
<?php header('Content-Type: application/rss+xml'); ?>
<?='<?xml version="1.0" encoding="utf-8"?>'?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<channel>
<title><![CDATA[Neon Genesis Kode]]></title>
<link>http://govnokod.ru</link>
<description><![CDATA[Свежие комментарии]]></description>
<pubDate><?=date(DATE_RSS)?></pubDate>
<language>ru-ru</language>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<ttl>3600</ttl>
<?php
$curl_context = curl_init();
curl_setopt($curl_context, CURLOPT_URL, 'http://146.185.130.46/ngk/api/v1/latest');
curl_setopt($curl_context, CURLOPT_RETURNTRANSFER, 1);
$raw_data = curl_exec($curl_context);
curl_close($curl_context);
$data = JSON_decode($raw_data);
foreach($data as $item) { ?>
<item>
<title><![CDATA[Комментарий к говнокоду #<?=$item->thread_id?>]]></title>
<link>http://govnokod.ru/<?=$item->thread_id?>#comment<?=$item->comment_id?></link>
<guid>http://govnokod.ru/<?=$item->thread_id?>#comment<?=$item->comment_id?></guid>
<description><![CDATA[<?=$item->text?>]]></description>
<pubDate><?=date(DATE_RSS, strtotime($item->posted))?></pubDate>
</item>
<?php } ?>
</channel>
</rss>
Обычный пыхокод. Листайте дальше.
inkanus-gray,
17 Августа 2016
+320
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
import java.io.*;
public class word {
static int count = 0;
public static void main (String[] args)throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String word = reader.readLine();
reader.close();
String r = word.replaceAll("\\d|\\s|\\\\|/|\\]|\\[|\\`|\\~|\\.|\\>|\\<|\\,|\\;|\\:|\\\"|\\'|\\||\\?|\\!|\\@|\\#|\\№|\\$|\\%|\\^|\\&|\\*|\\)|\\(|\\-|\\_|\\+|\\=|\\}|\\{","");
char[] letters = r.toCharArray();
for(int i = 0;i<letters.length;i++){
count++;
}
System.out.println("Кол-во букв:" + count);
}
}
программа считывает кол-во букв в слове, которое вводит юзер
TopCodeMonkey,
17 Августа 2016
+14
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
public class DooBeeDooBeeDo {
public static void main(String[] args){
int x = 1;
while(x<3){
System.out.print("Doo");
System.out.print("Bee");
x=x+1;
}
if(x==3){
System.out.print("Do");
}
}
}
одно из старых упражнений
TopCodeMonkey,
17 Августа 2016
+270
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
$("#page1").click(function(){
$(".ag1").fadeIn(2500);
});
$("#page2").click(function(){
$(".ag2").fadeIn(2500);
});
$("#page3").click(function(){
$(".ag3").fadeIn(2500);
});
$("#page4").click(function(){
$(".ag4").fadeIn(2500);
});
$("#page5").click(function(){
$(".ag5").fadeIn(2500);
});
$("#page6").click(function(){
$(".ag6").fadeIn(2500);
});
$("#page7").click(function(){
$(".ag7").fadeIn(2500);
});
$("#page8").click(function(){
$(".ag8").fadeIn(2500);
});
$("#page9").click(function(){
$(".ag9").fadeIn(2500);
});
$("#page10").click(function(){
$(".ag10").fadeIn(2500);
});
$("#page11").click(function(){
$(".ag11").fadeIn(2500);
});
$("#page12").click(function(){
$(".ag12").fadeIn(2500);
});
$("#page13").click(function(){
$(".ag13").fadeIn(2500);
});
$("#page14").click(function(){
$(".ag14").fadeIn(2500);
});
$("#page15").click(function(){
$(".ag15").fadeIn(2500);
});
$("#page16").click(function(){
$(".ag16").fadeIn(2500);
});
$("#page17").click(function(){
$(".ag17").fadeIn(2500);
});
$("#page18").click(function(){
$(".ag18").fadeIn(2500);
});
$("#page19").click(function(){
$(".ag19").fadeIn(2500);
});
$("#page20").click(function(){
$(".ag20").fadeIn(2500);
});
$("#page21").click(function(){
$(".ag21").fadeIn(2500);
});
$("#page22").click(function(){
$(".ag22").fadeIn(2500);
});
$("#page23").click(function(){
$(".ag23").fadeIn(2500);
});
$("#page24").click(function(){
Из Азербайджана с любовью.
mikakak,
16 Августа 2016
+319
- 1
- 2
- 3
- 4
- 5
if (("/dir/" + TXT_FILE_NAME).equals(fileName))
processTxtFiles(TXT_FILE_NAME);
else if (fileName.endsWith(TXT_FILE_NAME))
processTxtFiles(TXT_FILE_NAME);
else if ...
Зачем первые две строки?
-EZ-,
16 Августа 2016
+317
- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
/**
* 连接指定的手环
*
* @param callback
*/
public void connect(BluetoothDevice device, final ActionCallback callback) {
this.io.connect(context, device, callback);
}
public void setDisconnectedListener(NotifyListener disconnectedListener) {
this.io.setDisconnectedListener(disconnectedListener);
}
/**
* 和手环配对, 实际用途未知, 不配对也可以做其他的操作
*
* @return data = null
*/
public void pair(final ActionCallback callback) {
ActionCallback ioCallback = new ActionCallback() {
@Override
public void onSuccess(Object data) {
BluetoothGattCharacteristic characteristic = (BluetoothGattCharacteristic) data;
Log.d(TAG, "pair result " + Arrays.toString(characteristic.getValue()));
if (characteristic.getValue().length == 1 && characteristic.getValue()[0] == 2) {
callback.onSuccess(null);
} else {
callback.onFail(-1, "respone values no succ!");
}
}
@Override
public void onFail(int errorCode, String msg) {
callback.onFail(errorCode, msg);
}
};
this.io.writeAndRead(Profile.UUID_CHAR_PAIR, Protocol.PAIR, ioCallback);
}
public BluetoothDevice getDevice() {
return this.io.getDevice();
}
/**
* 读取和连接设备的信号强度RSSI值
*
* @param callback
* @return data : int, rssi值
*/
public void readRssi(ActionCallback callback) {
this.io.readRssi(callback);
}
/**
* 读取手环电池信息
*
* @return {@link BatteryInfo}
*/
public void getBatteryInfo(final ActionCallback callback) {
ActionCallback ioCallback = new ActionCallback() {
@Override
public void onSuccess(Object data) {
BluetoothGattCharacteristic characteristic = (BluetoothGattCharacteristic) data;
Log.d(TAG, "getBatteryInfo result " + Arrays.toString(characteristic.getValue()));
if (characteristic.getValue().length == 10) {
BatteryInfo info = BatteryInfo.fromByteData(characteristic.getValue());
callback.onSuccess(info);
} else {
callback.onFail(-1, "result format wrong!");
}
}
@Override
public void onFail(int errorCode, String msg) {
callback.onFail(errorCode, msg);
}
};
this.io.readCharacteristic(Profile.UUID_CHAR_BATTERY, ioCallback);
}
/**
* 让手环震动
*/
public void startVibration(VibrationMode mode) {
byte[] protocal;
switch (mode) {
case VIBRATION_WITH_LED:
protocal = Protocol.VIBRATION_WITH_LED;
break;
case VIBRATION_10_TIMES_WITH_LED:
protocal = Protocol.VIBRATION_10_TIMES_WITH_LED;
break;
case VIBRATION_WITHOUT_LED:
protocal = Protocol.VIBRATION_WITHOUT_LED;
break;
default:
return;
}
@chineesedoc
iramailforspam,
15 Августа 2016
+319
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
template<typename OpeningBracketRange,
typename ClosingBracketRange,
typename StopTokenRange,
typename CommentBlockRangePairRange,
typename RecursiveCommentBlockRangePairRange>
Meta::EnableIf<
IsFiniteForwardRange<OpeningBracketRange>::_ &&
IsFiniteForwardRange<ClosingBracketRange>::_ &&
IsFiniteForwardRange<StopTokenRange>::_ &&
IsFiniteForwardRange<CommentBlockRangePairRange>::_ &&
IsFiniteForwardRange<RecursiveCommentBlockRangePairRange>::_,
decltype(Meta::Val<R>().Take(0))> ReadRecursiveBlock(int& counter, size_t* ioIndex,
OpeningBracketRange openingBracket, ClosingBracketRange closingBracket, StopTokenRange stopToken,
CommentBlockRangePairRange commentBlocks, RecursiveCommentBlockRangePairRange recursiveCommentBlocks)
{
R start = me();
size_t index = 0;
const size_t openingBracketLen = openingBracket.Count();
const size_t closingBracketLen = closingBracket.Count();
const size_t stopTokenLen = stopToken.Count();
while(!me().Empty() && counter!=0)
{
if(openingBracketLen!=0 && me().StartsWith(openingBracket))
{
counter++;
me().PopFrontExactly(openingBracketLen);
index += openingBracketLen;
continue;
}
if(closingBracketLen!=0 && me().StartsWith(closingBracket))
{
counter--;
me().PopFrontExactly(closingBracketLen);
index += closingBracketLen;
continue;
}
if(stopTokenLen!=0 && me().StartsWith(stopToken))
{
me().PopFrontExactly(stopTokenLen);
index += stopTokenLen;
break;
}
bool commentFound = false;
for(auto& commentBlock: commentBlocks)
{
commentFound = me().StartsWith(commentBlock.Get<0>());
if(!commentFound) continue;
const size_t commentBlockOpeningLen = commentBlock.Get<0>().Count();
const size_t commentBlockClosingLen = commentBlock.Get<1>().Count();
me().PopFrontN(commentBlockOpeningLen);
index += commentBlockOpeningLen;
me().FindAdvance(commentBlock.Get<1>(), &index);
me().PopFrontN(commentBlockClosingLen);
index += commentBlockClosingLen;
break;
}
if(commentFound) continue;
for(auto& commentBlock: recursiveCommentBlocks)
{
commentFound = me().StartsWith(commentBlock.Get<0>());
if(!commentFound) continue;
int commentCounter = 1;
ReadRecursiveBlock(commentCounter, &index, commentBlock.Get<0>(), commentBlock.Get<1>(), null, null);
break;
}
if(commentFound) continue;
me().PopFront();
}
if(ioIndex!=null) (*ioIndex) += index;
return start.Take(index);
}
Это мои последние достижения в написании сверх универсального обобщённого кода.
Начиналось всё с функции, которая парсила блок кода до закрывающей фигурной скобки, учитывая встречающиеся открывающие скобки. Затем появилась поддержка комментариев и строк. Позже я решил, что нечего привязываться к какому-то конкретному языку, ведь можно же таким же образом парсить другой язык, где вместо скобок begin end и комментарии по-другому оформляются.
А потом я подумал, зачем вообще привязывать типы параметров к строкам и массивам строк? И почему код, который парсится, вообще должен быть строкой, хранящейся в памяти непрерывно? В итоге мои размышления привели к такой реализации, которая способна парсить всё подряд, в том числе и связные списки, причём необязательно состоящие из символов. При этом открывающуюся скобку можно передать связным списком, закрывающуюся - массивом, а блоки комментариев передавать как массивом кортежей, так и хеш-таблицей.
При этом эта функция относится к классу примеси и наследованием её можно подмешать к любому классу, имеющему нужные методы.
gammaker,
15 Августа 2016
+261
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
/* load config */
for (i = 0; ; i++) {
conf[0] = '\0';
switch (i) {
case 0:
/* ~ */
snprintf(conf, sizeof conf, "%s/.%s",
pwd->pw_dir, SWM_CONF_FILE);
break;
case 1:
/* global */
snprintf(conf, sizeof conf, "/etc/%s",
SWM_CONF_FILE);
break;
case 2:
/* ~ compat */
snprintf(conf, sizeof conf, "%s/.%s",
pwd->pw_dir, SWM_CONF_FILE_OLD);
break;
case 3:
/* global compat */
snprintf(conf, sizeof conf, "/etc/%s",
SWM_CONF_FILE_OLD);
break;
default:
goto noconfig;
}
if (strlen(conf) && stat(conf, &sb) != -1)
if (S_ISREG(sb.st_mode)) {
cfile = conf;
break;
}
}
Вот так spectrwm грузит конфиги.
codemonkey,
15 Августа 2016
+273
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
#include <math.h>
#include <stdio.h>
double DoubleToTheInt(double base, int power) {
return pow(base, power);
}
int main() {
// приводим к указателю на функуцию с обратным порядком аргументов
double (*IntPowerOfDouble)(int, double) =
(double (*)(int, double))&DoubleToTheInt;
printf("(0.99)^100: %lf \n", DoubleToTheInt(0.99, 100));
printf("(0.99)^100: %lf \n", IntPowerOfDouble(100, 0.99));
}
"Изящный способ отстрелить себе ногу по самую голову."
Утащено с Хабры.
Vindicar,
15 Августа 2016
+341
- 1
- 2
$dom = new DOMDocument;
$dom->loadHTML('<?xml encoding="UTF-8">' . $document);
Выжал самое интересное.
Кто угадает, зачем к документу прилепляется строка '<?xml encoding="UTF-8">', тому ничего. Но без неё не работает. Точнее, работает, но неправильно.
inkanus-gray,
13 Августа 2016