Skip to content

Instantly share code, notes, and snippets.

@tystr
tystr / wma_offset.js
Created June 23, 2020 03:24
Tradovate weighted moving average script which allows setting an offset amount
const predef = require("./tools/predef");
const WMA = require("./tools/WMA");
class weightedMovingAverage {
init() {
this.wma = WMA(this.props.period);
}
map(d) {
return this.wma(d.value() - this.props.offset);
@tystr
tystr / chrome_app_mode.sh
Created May 3, 2019 15:30
Bash script to launch chrome in app mode on macOS
#!/bin/bash
# Launches chrome in app mode using the first argument to this command as the url.
if [ -z "$1" ]; then
echo "You must specify a full URL."
exit 1;
elif [[ ! $1 =~ ^https?:\/\/ ]]; then
echo "Url must begin with \"http://\" or \"https://\""
exit 1;
fi
<?php
namespace App\Response;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Response;
class TransparentImagePixelResponse extends Response
{
/**
@tystr
tystr / deploy.sh
Last active December 12, 2017 17:42
Simple bash script to first build then rsync a brunch application to multiple servers
#!/bin/bash
# This script assumes that you have the deployer ssh key in your home directory
# The ./public directory is deployed into the $DEPLOY_TO directory on the remote servers
RSYNC=/usr/bin/rsync
BRUNCH=/usr/local/bin/brunch
PRODUCTION_HOSTNAMES=("host1" "host2")
DEPLOY_TO=/var/www/application/current
DEPLOYER_SSH_KEY=$HOME/.ssh/id_rsa-deployer
LOGFILE=deploy.log
@tystr
tystr / changelog.sh
Last active October 26, 2017 18:16
Simple script for building a changelog since the last tag
#!/bin/bash
#
# Author: Tyler Stroud <tyler@tylerstroud.com>
# Date: 2017-10-25
#
# This script will build a changelog containing commit messages for all commits since the most recent tag.
# It will prepend a new entry using today's date and the specified tagname followed by the commit messages
# to CHANGELOG.md
#
# Usage:
@tystr
tystr / phpunit_bootstrap.php
Created August 8, 2011 23:56
Symfony2 PHPUnit Bootstrap
<?php
// include symfony2 bootstrap
include 'bootstrap.php.cache';
abstract class BaseTestCase extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
{
protected $client;
public function setUp()
@tystr
tystr / DoctrineFormHandler.php
Last active March 27, 2016 22:26
Doctrine Symfony2 Form Handler
<?php
namespace Form\Handler;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Persistence\ObjectManager;
use Form\Handler\FormHandlerInterface;
/**
@tystr
tystr / ModelManager.php
Last active January 5, 2016 00:02
Cache query result per request
<?php
// ...
private $repository;
private $cachedResults = [];
public function findAll()
{
@tystr
tystr / alias.php
Last active December 22, 2015 02:34
PHP Implementation of Vose's Alias Method
<?php
/**
* Implementation of Vose's Alias Method
*
* @param array $probabilities An array of probabilities
*
* @return int
*/
public function aliasMethod(array $probabilities)
{
@tystr
tystr / mongo-mms-agent
Last active December 18, 2015 02:09
init script for mongodb mms agent (http://mms.mongodb.com/help/monitoring/install/)
#!/bin/bash
#
# /etc/rc.d/init.d/mms-agent
#
# 10Gen Mongod montiroing service
# must edit the settings.py first and edit this file with the location of agent.py
#
# description: 10Gen monitoring service - need ot fix pid so we can shut it down
# chkconfig: - 90 10