Skip to content

Instantly share code, notes, and snippets.

View tdlm's full-sized avatar

Scott Weaver tdlm

View GitHub Profile
const sumArray = (a) => {
if ( typeof a == 'undefined' || !a || a.length < 2 ) { return 0; }
a.sort((a,b) => a - b).splice(0, 1)
a.splice(a.length - 1, 1);
if ( a.length < 3 ) { return 0; }
return a.reduce((a,b) => a+b);
};
const arrange = (str) => {
let words = str.split(' '), i = 0;
for (; i < words.length - 1; i++) {
if (
(0 === i % 2 && words[i].length > words[i + 1].length) ||
(1 === i % 2 && words[i].length < words[i + 1].length)
) {
let tmp = words[i];
words[i] = words[i + 1];
#!/bin/ruby
class BubbleSort
def initialize(unsorted_array)
@array = unsorted_array
@swaps = 0
end
def sort
@array.each_with_index do |val, key|
@tdlm
tdlm / advent_of_code-day1.rb
Last active December 9, 2016 21:24
Advent of Code
#!/bin/ruby
require "test/unit"
class GridMap
CARDINAL="NESW"
def initialize(directions)
@face = 'N'
@pointing = 0
@tdlm
tdlm / trie.rb
Last active December 1, 2016 01:08
Trie w/ Ruby
#!/bin/ruby
class Trie
@@root
def initialize
@@root = TrieNode.new
end
def add_word(word)
@tdlm
tdlm / trie.php
Last active December 1, 2016 01:30
Trie w/ Search
<?php
class Trie {
private $_root;
public function __construct() {
$this->_root = new TrieNode();
}
public function add($word) {
@tdlm
tdlm / magento.conf
Created November 23, 2016 22:45 — forked from jonathonbyrdziak/magento.conf
A configuration file for magento under nginx.
#####################################################
#
# Provided by the Magento Support Center
# http://magentosupport.help/knowledgebase/configuring-nginx-to-work-with-magento-advanced/
#
# Your Magento Tutorial specialists
#
server {
listen *:8080;
server_name fanatik.redrokk.com www.fanatikbike.com fanatikbike.com;
@tdlm
tdlm / processizer
Last active November 4, 2016 23:25
The idea of processizer is to list all running processes on the Mac and display the man page description inline. If there is no man page description, eventually this process would reach out to an external API and try to find a match, which it would cache locally. Holistically, the idea is to know what's running on your system.
#!/usr/bin/env bash
function get_process_description {
local __page=$(MANWIDTH=200 man "$@" 2>&1 | col -bx)
local __desc=$(echo "$__page" | pcregrep -M -o2 '(DESCRIPTION)\n(.*)' | sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba')
if [[ -z "$__desc" ]]; then
return 2
else
@tdlm
tdlm / ttfb.sh
Created September 12, 2016 19:29
Command to take average time-to-first-byte for a given URL
#!/usr/local/bin/bash
total=0.000
ttfbs=()
for i in `seq 1 5`
do
ttfb=$(curl -s -o /dev/null -w "%{time_starttransfer}" "$1")
total=$(scale=3;echo "$total+$ttfb" | bc)
done
#!/bin/bash
echo "Commencing Vocativ Base Setup as user: $USER"
cd /srv/www/
echo "Setting permissions..."
sudo touch /var/log/php5-fpm.log
echo "Copying vagrant ssh settings to root..."