This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import copy | |
import pygame | |
import argparse | |
LEFT = 1 | |
def rint(x): | |
if x % 1 >= 0.5: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
# This work is licensed under the terms of the MIT license. | |
# For a copy, see <https://opensource.org/licenses/MIT>. | |
""" | |
A hook to git that removes orphan files "*.pyc" and "*.pyo" for "*.py" | |
beeing deleted or renamed by git checkout. It also removes their empty parent | |
directories. | |
Place it to "my_local_repository/.git/hooks/post-checkout" and make it executable. | |
Nothing is cleaned for .py files deleted manually or by "git rm" etc. | |
Related to http://stackoverflow.com/q/1504724/448474 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Q | |
from django.utils import six | |
class MetaV(type): | |
# metaclass to automatically create an instance by . dot | |
def __getattr__(self, name): | |
if name.startswith('_'): | |
return super(self, MetaV).__getattr__(name) | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# free MIT license | |
def case_safe_id(id_15): | |
""" | |
Convert a 15 char case-sensitive Id to 18 char case-insensitive Salesforce Id. | |
Long 18 char Id are from SFDC API and from Apex. They are recommended by SF. | |
Short 15 char Id are from SFDC formulas if omitted to use func CASESAFEID(), | |
from reports or from parsed URLs in HTML. | |
The long and short form are interchangable as the input to Salesforce API or |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == models.py == | |
from salesforce import models | |
class RecordType(models.SalesforceModel): | |
sobject_type = models.CharField(max_length=40, sf_read_only=models.NOT_UPDATEABLE) | |
class Contact(models.Model): | |
last_name = models.CharField(max_length=80) | |
record_type = models.ForeignKey(RecordType, models.DO_NOTHING, blank=True, null=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Parse Salesforce report data in Python | |
details in my answer https://stackoverflow.com/a/45645135/448474 | |
""" | |
from collections import OrderedDict | |
from simple_salesforce import Salesforce | |
import pandas as pd | |
import json | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Getting Python's unittest results in a tearDown() method | |
https://stackoverflow.com/questions/4414234/getting-pythons-unittest-results-in-a-teardown-method#39606065 | |
""" | |
import unittest | |
class MyTest(unittest.TestCase): | |
def tearDown(self): | |
if hasattr(self._outcome, 'errors'): | |
# Python 3.4 - 3.10 (These two methods have no side effects) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* source from | |
http://stackoverflow.com/questions/13560037/effcient-way-to-find-longest-duplicate-string-for-python-from-programming-pearl | |
http://www.cs.bell-labs.com/cm/cs/pearls/longdup.c | |
/* Copyright (C) 1999 Lucent Technologies */ | |
/* From 'Programming Pearls' by Jon Bentley */ | |
/* longdup.c -- Print longest string duplicated M times */ | |
#include <stdlib.h> | |
#include <string.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Find the longest repeated substring. | |
"Efficient way to find longest duplicate string for Python (From Programming Pearls)" | |
http://stackoverflow.com/questions/13560037/ | |
The algorithm is based on "Prefix doubling". | |
The worst time complexity is O(n (log n)^2). Memory requirements are linear. | |
""" | |
import time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Horní odhad počtu stavů Rubikovy kostky po N tazích typu čtvrt-obrátka | |
# https://sciencemag.cz/umela-inteligence-se-sama-naucila-slozit-rubikovu-kostku/#post-3981572954 | |
Počty stavů po daném počtu tahů v jedné ze tří rovin | |
O: - 0 | |
1: L l R r 4 | |
2: LL LR Lr lR lr RR 6 | |
3: LLR LLr LRR lRR 4 |