Skip to content

Instantly share code, notes, and snippets.

@xuru
xuru / commit-msg
Last active September 16, 2015 15:40
A commit message that adds the commit message to a jira ticket as a comment. Must have the jira ticket number in the commit message, or the branch name.
#!/usr/bin/env python
import distutils.spawn
import re
import sys
if '/usr/local/lib/python2.7/site-packages' not in sys.path:
sys.path.insert(0, '/usr/local/lib/python2.7/site-packages')
if '/Library/Python/2.7/site-packages' not in sys.path:
@xuru
xuru / post-checkout
Created September 16, 2015 15:49
A post-checkout git hook that automatically sets your jira ticket to "in progress". The Jira ticket number must be in the branch name (i.e. feature/WEB-1234_fix_for_an_issue). Could be modified to set all other "in progress" tickets to no in progress with a little effort.
#!/usr/bin/env python
import distutils.spawn
import sys
import re
if '/usr/local/lib/python2.7/site-packages' not in sys.path:
sys.path.insert(0, '/usr/local/lib/python2.7/site-packages')
@xuru
xuru / models.py
Created January 5, 2016 21:16
one to one mapping sqlalchemy
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import validates
db = SQLAlchemy()
class User(db.Model):
__tablename__ = "user"
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.Unicode)
@xuru
xuru / example.sql
Last active March 19, 2016 00:25
sql shit
/*
This is just an example of our current db and number of dups
*/
SELECT
MobilePhone, count(MobilePhone)
FROM TerminalMemberTable
WHERE IsActive = 1 AND LastTransaction IS NOT NULL
GROUP BY MobilePhone
HAVING count(MobilePhone) > 1
from flask_restful import Resource
class UserProfileImageResource(Resource):
@jwt_required()
def post(self, user_id):
"""
/v1/users/<user_id>/signed_post
"""
@xuru
xuru / bloop_test.py
Last active September 12, 2017 23:50
Testing some inheritance flows
import random
import uuid
from string import ascii_letters
from enum import Enum
import boto3
from datetime import datetime, timezone
from bloop import (
BaseModel, Column, String, UUID, GlobalSecondaryIndex, LocalSecondaryIndex, Engine, DateTime, Boolean,
Set
@xuru
xuru / factories.py
Last active July 10, 2020 16:43
Factory boy example
# -*- coding: utf-8 -*-
"""Factories to help in tests."""
import random
from datetime import date
import factory
# noinspection PyPackageRequirements
from faker import Faker
from .database import db
from xxx.controllers import User
@xuru
xuru / Espresso%20Soda.tmTheme
Created February 4, 2018 22:33
Sublime Text settings
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Espresso Soda</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@xuru
xuru / onStart.sh
Last active June 23, 2020 23:19
template
#!/bin/bash
set -e
# This script stops a SageMaker notebook once it's idle for more than 1 hour (default time)
# You can change the idle time for stop using the environment variable below.
# If you want the notebook the stop only if no browsers are open, remove the --ignore-connections flag
IDLE_TIME=10800
echo "Fetching the autostop script"
@xuru
xuru / example.py
Created April 26, 2022 18:06
Alpaca SSE
b64_encoded_auth = base64.b64encode(f"{APCA_API_KEY_ID}:{APCA_API_SECRET_KEY}".encode()).decode()
self.session.headers.update({"Authorization": f"Basic {b64_encoded_auth}"})
with EventSource(url, session=self.session, **kwargs) as client:
client.on_error = process_error
client.add_event_listener('message', callback=callback)
client.open()