This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open3' | |
def tail_and_quit(filename, regex_to_match) | |
cmd = "tail -n0 -f #{filename}" # bash tail -f command | |
Open3.popen2e('bash', '-c', cmd) do |i,oe,t| # input, output/error, process | |
oe.each do |line| | |
puts line | |
break if line.match(/#{regex_to_match}/) | |
end | |
Process.kill('INT', t.pid) # kill the tail process after matching string | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess, re | |
def tail_and_quit(filename, regex_to_match): | |
try: | |
f = subprocess.Popen(['tail', '-F', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
while True: | |
line = f.stdout.readline() | |
match = re.search(regex_to_match, line) | |
if match: break | |
finally: f.kill() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
def parse_request_data(f): | |
@wraps(f) | |
def parse(*args, **kwargs): | |
json_type = False | |
for header in request.headers: | |
if header[0] == 'Content-Type': | |
if "application/json" in header[1].lower(): | |
json_type = True | |
data = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_true_or_false(some_array): | |
if type(some_array) == list: | |
array = enumerate(some_array) | |
else: | |
array = some_array.iteritems() | |
for key, value in array: | |
if type(value) in (dict, list): | |
parse_true_or_false(some_array[key]) | |
else: | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# tomcat | |
# | |
# chkconfig: 345 96 30 | |
# description: Start up the Tomcat servlet engine. | |
# | |
# processname: java | |
# pidfile: /var/run/tomcat.pid | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uniquePush = (arr, item) => { | |
if ( arr.indexOf(item) === -1) { | |
arr.push(item) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def trendline(x, y): | |
# y = mx + b, where m = slope and b = offset | |
return "f(x) = {0}x + {1}".format(slope(x, y), offset(x, y)) | |
def sum_xy(x, y): | |
s = float(0) | |
for i in range(len(x)): | |
s += x[i] * y[i] | |
return s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import ScatterPlot from "./ScatterPlot-with-trendline" | |
data={[[0, 3],[5, 13],[10, 22],[15, 36],[20, 48],[25, 59],[30, 77],[35, 85],[40, 95],[45, 105],[50, 120],[55, 150],[60, 147],[65, 168],[70, 176],[75, 188],[80, 199],[85, 213],[90, 222],[95, 236],[100, 249]]} | |
export default class LinearGraph extends React.Component { | |
render() { | |
return <ScatterPlot data={data} /> | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from subprocess import Popen, PIPE | |
# Equivilent to `ps ax|grep search_string` | |
p2 = Popen(["grep", search_string], stdin=PIPE, stdout=PIPE) # search_string | |
p1 = Popen(["ps", "ax"], stdout=p2.stdin) | |
# Break up results into invidual lines | |
results = p2.communicate()[0].split("\n") | |
# Now iterate thru the list, filter out grep, and print pids |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<style> | |
.overlay { | |
position: absolute; | |
top: 0; | |
left: 0px; | |
bottom: 0px; | |
right: 0px; | |
z-index: 2; |
OlderNewer