Skip to content

Instantly share code, notes, and snippets.

@ktraff
ktraff / moment utc.js
Created August 14, 2014 18:58
Convert UTC dates to local time using Moment.js
$(function(){
setInterval(function(){
var divUtc = $('#divUTC');
var divLocal = $('#divLocal');
//put UTC time into divUTC
divUtc.text(moment.utc().format('YYYY-MM-DD HH:mm:ss'));
//get text from divUTC and conver to local timezone
var localTime = moment.utc(divUtc.text()).toDate();
localTime = moment(localTime).format('YYYY-MM-DD HH:mm:ss');

VM Setup

Installed SSH for remote access.

sudo apt-get install openssh-server

Set networking as Bridged Adapter. In VirtualBox, Machine > Settings > Network > Attached To = "Bridged Adapter".

sudo reboot
@ktraff
ktraff / Random CSV Timeseries Generator.py
Last active December 21, 2016 20:08
Generates pseudo-random timeseries data and saves to a csv file.
import random
import datetime
from datetime import timedelta
import csv
col_count = 5
num_items = 1000
cur_date = datetime.datetime.now()
with open('timeseries.csv', 'wb') as csvfile:
@ktraff
ktraff / 0_reuse_code.js
Created May 20, 2014 15:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ktraff
ktraff / Amazon S3 Backup.py
Last active August 29, 2015 13:59
An example script that uses Boto to upload a collection of files to Amazon.
"""
A script that backs up the database and sends the compressed output to an S3 bucket
"""
import os
import sys
import glob
import subprocess
import contextlib
import functools
import multiprocessing
@ktraff
ktraff / Check Website Status
Last active August 29, 2015 13:57
Check the status of a website and send an email if it is down
#!/bin/bash
# Script that checks the health status of a website and
# sends notifications if the website is unavailable.
HOST='website.com'
status=`curl -L -o /dev/null --silent --head --write-out '%{http_code}\n' $HOST`
if [ $status != 200 ]; then
echo "$HOST received a status of $status." | mail -s "$HOST is down" "johnsmith@gmail.com"
fi
@ktraff
ktraff / wp-config.multi.php
Created January 14, 2014 13:34
PHP wp-config file for multiple wordpress environments.
<?php
$current_config = __DIR__ . '/' . $_SERVER['HTTP_HOST'] . '.config.php';
if (file_exists($current_config))
require_once $current_config;
else {
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
@ktraff
ktraff / list.js
Last active December 25, 2015 08:59
_.list([1, 2, 3, 4, 5, 6, 7]).right(4).val() // 5
@ktraff
ktraff / _struct.zipper.js
Created October 12, 2013 14:15
An example of an Underscore zipper.
_.zipper([1, 2, 3, 4, 5, 6, 7]).right(4).left().val() // 4
doubleUs x y = doubleMe x + doubleMe y