Skip to content

Instantly share code, notes, and snippets.

@satiani
satiani / sample.rs
Last active February 7, 2019 00:57
let mut guard_stats: HashMap<u16, (u16, [u16; 60])> = HashMap::new();
let mut current_guard_id: u16 = 0;
let mut current_sleep_start_time: NaiveDateTime = NaiveDateTime::from_timestamp(0, 0);
for entry in log_entries {
match entry.entry_type {
EntryType::StartedShift(guard_id) => current_guard_id = guard_id,
EntryType::StartedSleeping => current_sleep_start_time = entry.date_time,
EntryType::WokeUp => {
let _entry = guard_stats.entry(current_guard_id);
let mut _temp0 = 0;
@satiani
satiani / money_poc.py
Last active September 26, 2017 19:39
Gist for SQLAlchemy question
from sqlalchemy import Column, Integer, String, create_engine, func
from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta
from sqlalchemy.orm.descriptor_props import CompositeProperty
from sqlalchemy.sql.functions import GenericFunction
from sqlalchemy.orm import composite, sessionmaker
from sqlalchemy.sql.expression import case
import sqlalchemy.types as types
class Money(object):
def __init__(self, amount, currency):
import base64
import urllib
import codecs
from Crypto.Cipher import AES
from Crypto.Hash import MD5
temp_token = "value from propay"
temp_token = codecs.encode(temp_token, 'utf-8')
settings = {
define(['jquery',
'underscore',
'lib/forge/cipher',
'lib/forge/aes',
'lib/forge/md5',
'lib/forge/util'], function ($, _, _Cipher, _CipherAES, _CipherMD5, _CipherUtil) {
var forge = {},
Cipher = _Cipher(forge),
CipherAES = _CipherAES(forge),
define(['jquery',
'underscore',
'balanced',
'lib/forge/cipher',
'lib/forge/aes',
'lib/forge/md5',
'lib/forge/util'], function ($, _, balanced, _Cipher, _CipherAES, _CipherMD5, _CipherUtil) {
var forge = {},
Cipher = _Cipher(forge),
def a():
try:
return True
finally:
return False
print "The result of the function is: %s" % a()
print
print "The disassembly is:"
import dis
@satiani
satiani / app.py
Last active December 28, 2015 10:59
How to work around the caching of wtforms validator message translations
from flask import Flask, request, jsonify
from flask.ext.wtf import Form, TextField, Email
from flask.ext.babel import get_translations, lazy_gettext as __
from flask.json import JSONEncoder
from speaklater import make_lazy_string, is_lazy_string
class CustomTranslations(object):
def babel_gettext(self, s):
return get_translations().ugettext(s)
import sys
class TestContext(object):
def __init__(self):
self.entered = False
self.exited = False
def __enter__(self):
self.entered = True
def __exit__(self, exc_type, exc_value, tb):
self.exited = True
class TestContext(object):
def __init__(self):
self.entered = False
self.exited = False
def __enter__(self):
self.entered = True
def __exit__(self):
self.exited = True
rom flask import Flask
app = Flask(__name__)
@app.teardown_request
def teardown(exc = None):
if exc is not None:
print "An exception has occured!"
try: