- 1
- 2
var m = map[int]string { 1: "one", 2: "two", 3: "three", }
if val, ok := m[3]; ok { fmt.Printf("Yes! %s\n",val) } else { fmt.Println("No!") }
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 150
+96
var m = map[int]string { 1: "one", 2: "two", 3: "three", }
if val, ok := m[3]; ok { fmt.Printf("Yes! %s\n",val) } else { fmt.Println("No!") }
Почему в Go первое присваивание надо писать через =
А то что в if через :=
http://ideone.com/cPf2cw
http://ideone.com/fork/cPf2cw
+118
... *sizeof(uint32_t)
Правильно. А то вдруг кто его переопределит.
+174
Float f = 1.25f;
int i = Float.floatToIntBits(f);
i++;
f = Float.intBitsToFloat(i);
//I wanted 2.25, but got 1.2500001 instead.
http://stackoverflow.com/questions/9921690/java-increment-through-float-floattointbits
+174
static String asHex(int i){
return
Joiner.on( " " ).join(
Splitter.fixedLength( 4 ).split(
String.format("%s8", Integer.toHexString(i))
.replace(' ', '0')
)
);
}
LINQ-мышление в жабе.
+171
public abstract class BaseDateTime
extends AbstractDateTime
implements ReadableDateTime, Serializable {
/** The millis from 1970-01-01T00:00:00Z */
private volatile long iMillis;
/** The chronology to use */
private volatile Chronology iChronology;
/////////////////////////////////////////////////////////////////
/*
* DateTime is thread-safe and immutable, provided that the Chronology is as well.
* All standard Chronology classes supplied are thread-safe and immutable.
*
* @see MutableDateTime
*/
public final class DateTime
extends BaseDateTime
Любителям joda-time.
Cмущает меня этот volatile, который приходит в немутабельный класс от родителя.
+166
package com.sun.jersey.core.util;
public class KeyComparatorLinkedHashMap<K, V>
extends KeyComparatorHashMap<K, V>
....
public class StringKeyIgnoreCaseMultivaluedMap<V>
extends KeyComparatorLinkedHashMap<String, List<V>>
....
public class StringKeyStringValueIgnoreCaseMultivaluedMap
extends StringKeyIgnoreCaseMultivaluedMap<String> {
....
Женерики не нужны.
+173
private static String formatDateFull(Calendar date) {
if (date == null)
return " ";
else
try {
return dateOutFormatFull.format(date.getTime());
} catch(Exception ex) {
return " ";
}
}
private static final SimpleDateFormat dateOutFormatFull = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSS");
+191
var bytes = new byte[] {0, 0, 0, 1};
var littleEndianBytes = bytes.Reverse().ToArray();
Single x = BitConverter.ToSingle(littleEndianBytes, 0);
http://stackoverflow.com/questions/1603295/fast-way-to-swap-bytes-in-array-from-big-endian-to-little-endian-in-c-sharp
Обратный порядок байт.
http://stackoverflow.com/a/2473895
I use LINQ, Chuck Norris said.
Фраза просто убила. Они совсем уже одурели?
+166
case OP_PSUM_ABS_DIFF:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PSADBW, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_LOWB:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PUNPCKLBW, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_LOWW:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PUNPCKLWD, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_LOWD:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PUNPCKLDQ, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_LOWQ:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PUNPCKLQDQ, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_LOWPS:
x86_sse_alu_ps_reg_reg (code, X86_SSE_UNPCKL, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_LOWPD:
x86_sse_alu_pd_reg_reg (code, X86_SSE_UNPCKL, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_HIGHB:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PUNPCKHBW, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_HIGHW:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PUNPCKHWD, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_HIGHD:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PUNPCKHDQ, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_HIGHQ:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PUNPCKHQDQ, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_HIGHPS:
x86_sse_alu_ps_reg_reg (code, X86_SSE_UNPCKH, ins->sreg1, ins->sreg2);
break;
case OP_UNPACK_HIGHPD:
x86_sse_alu_pd_reg_reg (code, X86_SSE_UNPCKH, ins->sreg1, ins->sreg2);
break;
case OP_PACKW:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PACKSSWB, ins->sreg1, ins->sreg2);
break;
case OP_PACKD:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PACKSSDW, ins->sreg1, ins->sreg2);
break;
case OP_PACKW_UN:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PACKUSWB, ins->sreg1, ins->sreg2);
break;
case OP_PACKD_UN:
x86_sse_alu_sse41_reg_reg (code, X86_SSE_PACKUSDW, ins->sreg1, ins->sreg2);
break;
case OP_PADDB_SAT_UN:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PADDUSB, ins->sreg1, ins->sreg2);
break;
case OP_PSUBB_SAT_UN:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PSUBUSB, ins->sreg1, ins->sreg2);
break;
case OP_PADDW_SAT_UN:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PADDUSW, ins->sreg1, ins->sreg2);
break;
case OP_PSUBW_SAT_UN:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PSUBUSW, ins->sreg1, ins->sreg2);
break;
case OP_PADDB_SAT:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PADDSB, ins->sreg1, ins->sreg2);
break;
case OP_PSUBB_SAT:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PSUBSB, ins->sreg1, ins->sreg2);
break;
case OP_PADDW_SAT:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PADDSW, ins->sreg1, ins->sreg2);
break;
case OP_PSUBW_SAT:
x86_sse_alu_pd_reg_reg (code, X86_SSE_PSUBSW, ins->sreg1, ins->sreg2);
break;
https://github.com/mono/mono/blob/master/mono/mini/mini-x86.c#L2481
+179
$.datepicker.formatDate('yy-mm-dd', new Date(2007, 1 - 1, 26));
Форматирование даты в жс. Без jQuery ясное дело не обойтись.
If you are already using jQuery UI in your project, you can use the built-in datepicker method for formatting your date object:
http://stackoverflow.com/a/7022296
Раз уж неделя стековерфловочки...