- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
def razmer(arr):
b = len (arr) - 1
return (array_prov(arr,b))
def array_prov (arr,b):
if b == 0:
return arr[b]
else:
return (arr[b]+array_prov (arr, b-1))
a = [10,12,14,15,18]
print (razmer (a))
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
def razmer(arr):
b = len (arr) - 1
return (array_prov(arr,b))
def array_prov (arr,b):
if b == 0:
return arr[b]
else:
return (arr[b]+array_prov (arr, b-1))
a = [10,12,14,15,18]
print (razmer (a))
0
def print_message(num_of_times) {
for i in range(num_of_times) {
print("Bython is awesome!");
}
}
if __name__ == "__main__" {
print_message(10);
}
Python with braces. Because Python is awesome, but whitespace is awful.
https://pypi.org/project/Bython/
0
IT Оффтоп #196
#166: https://govnokod.ru/28574 https://govnokod.xyz/_28574
#167: https://govnokod.ru/28588 https://govnokod.xyz/_28588
#168: https://govnokod.ru/28607 https://govnokod.xyz/_28607
#169: https://govnokod.ru/28628 https://govnokod.xyz/_28628
#170: https://govnokod.ru/28653 https://govnokod.xyz/_28653
#171: (vanished) https://govnokod.xyz/_28665
#172: https://govnokod.ru/28675 https://govnokod.xyz/_28675
#173: https://govnokod.ru/28681 https://govnokod.xyz/_28681
#174: https://govnokod.ru/28689 https://govnokod.xyz/_28689
#175: https://govnokod.ru/28696 https://govnokod.xyz/_28696
#176: https://govnokod.ru/28703 https://govnokod.xyz/_28703
#177: https://govnokod.ru/28709 https://govnokod.xyz/_28709
#178: https://govnokod.ru/28716 https://govnokod.xyz/_28716
#179: https://govnokod.ru/28726 https://govnokod.xyz/_28726
#180: https://govnokod.ru/28734 https://govnokod.xyz/_28734
#181: https://govnokod.ru/28739 https://govnokod.xyz/_28739
#182: https://govnokod.ru/28749 https://govnokod.xyz/_28749
#183: https://govnokod.ru/28777 https://govnokod.xyz/_28777
#184: https://govnokod.ru/28790 https://govnokod.xyz/_28790
#185: https://govnokod.ru/28794 https://govnokod.xyz/_28794
#186: https://govnokod.ru/28815 https://govnokod.xyz/_28815
#187: https://govnokod.ru/28833 https://govnokod.xyz/_28833
#188: https://govnokod.ru/28837 https://govnokod.xyz/_28837
#189: https://govnokod.ru/28840 https://govnokod.xyz/_28840
#190: https://govnokod.ru/28875 https://govnokod.xyz/_28875
#191: https://govnokod.ru/28878 https://govnokod.xyz/_28878
#192: https://govnokod.ru/28886 https://govnokod.xyz/_28886
#193: https://govnokod.ru/28911 https://govnokod.xyz/_28911
#194: https://govnokod.ru/28914 https://govnokod.xyz/_28914
#195: https://govnokod.ru/28917 https://govnokod.xyz/_28917
0
Политота #34
#4: (vanished) https://govnokod.xyz/_24822
#5: https://govnokod.ru/24868 https://govnokod.xyz/_24868
#6: (vanished) https://govnokod.xyz/_26648
#7: https://govnokod.ru/26673 https://govnokod.xyz/_26673
#8: https://govnokod.ru/27052 https://govnokod.xyz/_27052
#9: (vanished) https://govnokod.xyz/_27852
#10: https://govnokod.ru/28060 https://govnokod.xyz/_28060
#11: https://govnokod.ru/28091 https://govnokod.xyz/_28091
#12: https://govnokod.ru/28103 https://govnokod.xyz/_28103
#13: https://govnokod.ru/28144 https://govnokod.xyz/_28144
#14: https://govnokod.ru/28270 https://govnokod.xyz/_28270
#15: https://govnokod.ru/28341 https://govnokod.xyz/_28341
#16: https://govnokod.ru/28379 https://govnokod.xyz/_28379
#17: https://govnokod.ru/28394 https://govnokod.xyz/_28394
#18: https://govnokod.ru/28440 https://govnokod.xyz/_28440
#19: https://govnokod.ru/28572 https://govnokod.xyz/_28572
#20: https://govnokod.ru/28656 https://govnokod.xyz/_28656
#21: (vanished) https://govnokod.xyz/_28666
#22: https://govnokod.ru/28676 https://govnokod.xyz/_28676
#23: https://govnokod.ru/28684 https://govnokod.xyz/_28684
#24: https://govnokod.ru/28691 https://govnokod.xyz/_28691
#25: https://govnokod.ru/28698 https://govnokod.xyz/_28698
#26: https://govnokod.ru/28704 https://govnokod.xyz/_28704
#27: https://govnokod.ru/28711 https://govnokod.xyz/_28711
#28: https://govnokod.ru/28721 https://govnokod.xyz/_28721
#29: https://govnokod.ru/28728 https://govnokod.xyz/_28728
#30: (vanished) https://govnokod.xyz/_28747
#31: https://govnokod.ru/28757 https://govnokod.xyz/_28757
#32: https://govnokod.ru/28770 https://govnokod.xyz/_28770
#33: https://govnokod.ru/28835 https://govnokod.xyz/_28835
0
template <typename Key, typename Value, size_t TblPower = 2>
struct HashMap {
struct Node
{
Key k;
Value v;
Node *n;
Node(const Key &key, const Value &value) :
k(key), v(value), n(NULL) {}
Node(const Key &key) :
k(key), v(), n(NULL) {}
};
constexpr static size_t TblSize = 1U << TblPower;
Node *table[TblSize] = {nullptr};
HashMap() {
}
~HashMap() {
for(size_t i = 0; i < TblSize; i++)
{
Node *entry = table[i];
while(entry)
{
Node *prev = entry;
entry = entry->n;
delete prev;
}
table[i] = NULL;
}
}
size_t HashFunc(const Key &key) const
{
/// TODO: string hash?
// handle hash: handle pointers usually aligned
return (((size_t) key) >> 8) & (TblSize - 1);
}
// just in case: check existance or constant access
forceinline Value *GetPtr(const Key &key) const
{
size_t hashValue = HashFunc(key);
Node *entry = table[hashValue];
while(likely(entry))
{
if(entry->k == key)
return &entry->v;
entry = entry->n;
}
return nullptr;
}
Value &operator [] (const Key &key)
{
return GetOrAllocate(key);
}
#define HASHFIND(key) \
size_t hashValue = HashFunc(key); \
Node *prev = NULL; \
Node *entry = table[hashValue]; \
\
while(entry && entry->k != key) \
{ \
prev = entry; \
entry = entry->n; \
}
Node * noinline _Allocate(Key key, size_t hashValue, Node *prev, Node *entry)
{
entry = new Node(key);
if(unlikely(!entry))
{
static Node error(key);
return &error;
}
if(prev == NULL)
table[hashValue] = entry;
else
prev->n = entry;
return entry;
}
Value& GetOrAllocate(const Key &key)
{
HASHFIND(key);
if(unlikely(!entry))
entry = _Allocate(key,hashValue, prev, entry);
return entry->v;
}
// тут был ещё один метод, но в говнокод не влез
}
когда СГОРЕЛО от STL
0
struct HashArrayMap {
struct Node
{
Key k;
Value v;
Node(const Key &key, const Value &value) :
k(key), v(value){}
Node(const Key &key) :
k(key), v(){}
};
constexpr static size_t TblSize = 1U << TblPower;
GrowArray<Node> table[TblSize];
HashArrayMap() {
}
~HashArrayMap() {
}
size_t HashFunc(const Key &key) const
{
/// TODO: string hash?
// handle hash: handle pointers usually aligned
return (((size_t) key) >> 8) & (TblSize - 1);
}
// just in case: check existance or constant access
Value *GetPtr(const Key &key) const
{
size_t hashValue = HashFunc(key);
const GrowArray<Node> &entry = table[hashValue];
for(int i = 0; i < entry.count; i++)
{
if(entry[i].k == key)
return &entry[i].v;
}
return nullptr;
}
Value &operator [] (const Key &key)
{
return GetOrAllocate(key);
}
#define HASHFIND(key) \
GrowArray<Node> &entry = table[HashFunc(key)]; \
int i; \
for(i = 0; i < entry.count; i++) \
if( entry[i].k == key ) \
break;
Value& GetOrAllocate(const Key &key)
{
HASHFIND(key);
if(i == entry.count )
entry.Add(Node(key));
return entry[i].v;
}
bool Remove(const Key &key)
{
HASHFIND(key);
if(i != entry.count)
{
entry.RemoveAt(i);
return true;
}
return false;
}
#undef HASHFIND
};
когда СГОРЕЛО от STL
0
template<class T>
struct GrowArray
{
T *mem = nullptr;
size_t count = 0;
size_t alloc = 0;
GrowArray(size_t init = 0)
{
if(init)
Grow(init);
}
~GrowArray()
{
if(mem)
free(mem);
mem = nullptr;
count = 0;
alloc = 0;
}
// non-copyable
GrowArray(const GrowArray &) = delete;
GrowArray &operator = (const GrowArray &) = delete;
void noinline Grow(size_t size)
{
if(!size)
size = 32;
T *newMem = (T*)(mem? realloc(mem, sizeof(T) * size): malloc(sizeof(T)*size));
if(!newMem)
return;
alloc = size;
mem = newMem;
}
// TODO: insert/append
bool Add(const T& newVal)
{
size_t newIdx = count + 1;
if(unlikely(newIdx > alloc))
Grow(alloc * 2);
if(unlikely(newIdx > alloc))
return false;
mem[count] = newVal;
count = newIdx;
return true;
}
// TODO: test
bool RemoveAt(size_t idx)
{
if(idx < count)
memmove(&mem[idx], &mem[idx+1], sizeof(T) * (count - idx - 1));
if(idx <= count)
{
count--;
return true;
}
return false;
}
T& operator[](size_t i) const
{
return mem[i];
}
};
0
export type ReplaceNullToUndefined<T> = T extends (infer R)[]
? ReplaceNullToUndefined<R>[]
: T extends object
? {
[K in keyof T]: T[K] extends object
? ReplaceNullToUndefined<T[K]>
: null extends T[K]
? Exclude<T[K], null> | undefined
: T[K];
}
: T;
Заменяет все `null` на `undefined`
0
$tempname = '__temp__.apk';
copy($origname, $tempname);
exec('C:\Android\android-sdk\build-tools\34.0.0\aapt.exe dump badging ' . '"'.$tempname.'"', $output);
unlink($tempname);
Понадобилось по-быстрому наговнякать переименоватор apk-файлов. Решил метушню из манифеста вытянуть с помощью «aapt» из официальных «Android build tools». Оказалось, что «aapt» не может открыть файл, если его имя содержит символы за пределами базового ASCII. CHCP не помогает вообще никак.
При передаче в aapt имени в 866 выводится «asset... Asset path... is neither a directory nor file (type=1)», при передаче имени в других кодировках (1251, UTF-8) выводится сообщение «ziparchive... Invalid byte sequence». Так и не смог подобрать кодировку, в которой заработает.
Шёл 2024-й год.
0
Пиздец-оффтоп #97
#67: (vanished) https://govnokod.xyz/_28615
#68: https://govnokod.ru/28636 https://govnokod.xyz/_28636
#69: (vanished) https://govnokod.xyz/_28660
#70: (vanished) https://govnokod.xyz/_28667
#71: https://govnokod.ru/28677 https://govnokod.xyz/_28677
#72: https://govnokod.ru/28685 https://govnokod.xyz/_28685
#73: https://govnokod.ru/28692 https://govnokod.xyz/_28692
#74: https://govnokod.ru/28699 https://govnokod.xyz/_28699
#75: https://govnokod.ru/28705 https://govnokod.xyz/_28705
#76: https://govnokod.ru/28712 https://govnokod.xyz/_28712
#77: https://govnokod.ru/28722 https://govnokod.xyz/_28722
#78: https://govnokod.ru/28730 https://govnokod.xyz/_28730
#79: https://govnokod.ru/28736 https://govnokod.xyz/_28736
#80: https://govnokod.ru/28740 https://govnokod.xyz/_28740
#81: https://govnokod.ru/28750 https://govnokod.xyz/_28750
#82: https://govnokod.ru/28779 https://govnokod.xyz/_28779
#83: https://govnokod.ru/28788 https://govnokod.xyz/_28788
#84: https://govnokod.ru/28795 https://govnokod.xyz/_28795
#85: https://govnokod.ru/28808 https://govnokod.xyz/_28808
#86: (vanished) https://govnokod.xyz/_28814
#87: https://govnokod.ru/28817 https://govnokod.xyz/_28817
#88: https://govnokod.ru/28836 https://govnokod.xyz/_28836
#89: https://govnokod.ru/28843 https://govnokod.xyz/_28843
#90: https://govnokod.ru/28874 https://govnokod.xyz/_28874
#91: https://govnokod.ru/28880 https://govnokod.xyz/_28880
#92: https://govnokod.ru/28884 https://govnokod.xyz/_28884
#93: https://govnokod.ru/28889 https://govnokod.xyz/_28889
#94: https://govnokod.ru/28895 https://govnokod.xyz/_28895
#95: https://govnokod.ru/28904 https://govnokod.xyz/_28904
#96: https://govnokod.ru/28912 https://govnokod.xyz/_28912