Skip to content

Instantly share code, notes, and snippets.

def on_model_change(self, form, model, is_created=False):
if not is_created:
return
today = datetime.now().date()
start = form.start_date.data
end = form.end_date.data
if start <= today:
raise validators.ValidationError("'Start Date' must be a future date!")
@sithu
sithu / sqlite_backup.py
Created July 15, 2017 06:17 — forked from achimnol/sqlite_backup.py
A simple and safe SQLite3 backup script written in Python using ctypes + sqlite3 online backup API
#! /usr/bin/env python
# Of course, the author does not guarantee safety.
# I did my best by using SQLite's online backup API.
from __future__ import print_function
import sys, ctypes
from ctypes.util import find_library
SQLITE_OK = 0
SQLITE_ERROR = 1
SQLITE_BUSY = 5
@sithu
sithu / grafana-backup.sh
Created July 15, 2017 06:31 — forked from piotr1212/grafana-backup.sh
Grafana sqlite backup script
cat /usr/share/grafana/grafana-backup.sh
#!/bin/bash
DB="/var/lib/grafana/grafana.db"
BACKUP="/data/backup/grafana/grafana.db-$(date +%Y%m%d).bck"
SQLITE=/usr/bin/sqlite3
ZIP=/bin/gzip
${SQLITE} ${DB} ".backup ${BACKUP}"
${ZIP} ${BACKUP}
HelloWorld.deployed().then(helloworld=> console.log(helloworld.balance.call()))
// OR
HelloWorld.deployed().then(function(instance){helloworld=instance})
// THEN
helloworld.balance.call()
@sithu
sithu / gist:f9b3c67871ee2d3ec13c382fd1d93511
Created August 1, 2017 06:06 — forked from Bouke/gist:11261620
Multiple Python installations on OS X

Previous versions used homebrew to install the various versions. As suggested in the comments, it's better to use pyenv instead. If you are looking for the previous version of this document, see the revision history.

$ brew update
$ brew install pyenv
$ pyenv install 3.5.0
$ pyenv install 3.4.3
$ pyenv install 3.3.6
$ pyenv install 3.2.6
$ pyenv install 2.7.10

$ pyenv install 2.6.9

0x0c8cf01ae70831ac018160ffeedf2033b3364d7d
chain: ropsten
# Use automated Chrome to verify all contracts on etherscan.io
# You need to install Splinter package:
# pip install splinter
verify_on_etherscan: no
browser_driver: chrome
contracts:
chain: ropsten
# Use automated Chrome to verify all contracts on etherscan.io
# You need to install Splinter package:
# pip install splinter
verify_on_etherscan: no
browser_driver: chrome
contracts:
0x0006eC2E5Ca955d38cA133FBf440DDFab050804e
@sithu
sithu / latency.py
Last active February 4, 2018 05:15
In-class Exercise 1
"""
Question:
Pick one IP from each region, find network latency from via the below code snippet
(ping 3 times), and finally sort the average latency by region.
http://ec2-reachability.amazonaws.com/
Expected Output for all 15 regions:
1. us-west-1 [50.18.56.1] - 100ms (Smallest average latency)
2. xx-xxxx-x [xx.xx.xx.xx] - 200ms
3. xx-xxxx-x [xx.xx.xx.xx] - 300ms