Skip to content

Instantly share code, notes, and snippets.

@drhanlau
drhanlau / main.py
Last active May 27, 2018 18:17
Observer
if __name__ == "__main__":
stock_watcher = Observable()
american_observer = AmericanStockMarket()
stock_watcher.register(american_observer)
stock_watcher.publish('KLSE Market Update', price='+0.5')
@demoray
demoray / mytasks.py
Last active September 2, 2018 07:13
A custom complete method for luigi tasks that will re-run the task if any prerequisite task is newer
class MyTask(luigi.Task):
def complete(self):
def _get_last(outputs):
last = 0.0
for item in outputs:
if not item.exists():
continue
current = os.path.getmtime(item.path)
if current > last:
last = current
@hkage
hkage / pytest-cheatsheet.rst
Last active September 2, 2018 15:42
Cheatsheet for pytest features

pytest Cheatsheet

@pytest.fixture

  • scope: the scope for which this fixture is shared, one of “function” (default), “class”, “module”, “session”.
  • params: an optional list of parameters which will cause multiple invocations of the fixture function and all of the tests using it.
  • autouse: if True, the fixture func is activated for all tests that can see it. If False (the default) then an explicit reference is needed to activate the fixture.
  • ids: list of string ids each corresponding to the params so that they are part of the test id. If no ids are provided they will be generated automatically from the params.
anonymous
anonymous / config.json
Created December 16, 2014 13:16
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#fff",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#7bcc3a",
@APTy
APTy / multisig.py
Created January 30, 2016 01:46
two1 multisig
import two1.lib.bitcoin as bitcoin
from two1.lib.wallet import Wallet
wallet = Wallet()
# Collect public keys
p1_pubkey = wallet.get_payout_public_key()
p2_pubkey = wallet.get_change_public_key()
# Build multisig redeem script
def player_1(start_date=None, miss_output=False, miss_plot=False, sleep=False, sleep_time=1, plot=False, output=True, hold_max=1000, withdraw_max=500, withdraw_min=10):
user_key, day_info, amount, invested, profit, loss, game_active = bitcoin_game(start_date=start_date)
#print(user_key)
prev_predict = day_info[-1]
miss_colors = ['g']
while game_active == False:
#print(day_info[-1])
if day_info[-1] == 2: #equilavent of 100 i.e. good odds
#print('first option')
if invested < 100: #invest 100
@dhruvbaldawa
dhruvbaldawa / pytransitions.py
Created January 27, 2018 19:50
pytransitions example
from transitions import Machine
class Payments(models.Model):
STATES = {
'started': 'Started',
'captured': 'Captured',
'completed': 'Completed',
}
@danielfrg
danielfrg / clean-html-solr-pipeline.py
Last active May 6, 2019 12:45
Luigi pipeline that: 1. Reads a tdf file using pandas with html on the 'content' column and created another tdf with just the text of the html (beautifulsoup) 2. Indexes the text into a Solr collection using mysolr
import re
import json
import luigi
import pandas as pd
from mysolr import Solr
from bs4 import BeautifulSoup
class InputText(luigi.ExternalTask):
@samuell
samuell / luigi_dynamic_dependency_graph_definition.py
Last active March 21, 2020 14:57
Dynamically specify luigi data flow
import luigi
class ATask(luigi.Task):
def output(self):
return luigi.LocalTarget("atask_output.txt")
def run(self):
with self.output().open("w") as outfile:
outfile.write("Test")
@sokol815
sokol815 / quickalerts.md
Last active April 10, 2021 11:10
QuickAlerts Extension for Tradingview