This file contains 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 mean = (values) => { | |
let sum = values.reduce((previous, current) => current += previous); | |
return sum / values.length; | |
}; | |
const median = (arr) => { | |
const mid = Math.floor(arr.length / 2); | |
const sorted = [...arr].sort((a, b) => a - b); | |
return arr.length % 2 == 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid]; | |
}; |
This file contains 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> | |
<!-- CSS --> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/github.min.css" /> | |
<link rel="stylesheet" type="text/css" href="vendor-js/diff2html-3.0.0/bundles/css/diff2html.min.css" /> | |
<!-- Javascripts --> | |
<script type="text/javascript" src="vendor-js/diff2html-3.0.0/bundles/js/diff2html-ui.min.js"></script> | |
<script type="text/javascript" src="vendor-js/diff2html-3.0.0/bundles/js/diff2html.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> |
This file contains 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 com.google.common.collect.Multimap; | |
import com.google.common.collect.MultimapBuilder; | |
import java.util.Collection; | |
import java.util.function.Consumer; | |
public class AstWalker { | |
private final Multimap<Class<?>, Consumer<?>> enterNodeListeners = MultimapBuilder.linkedHashKeys().arrayListValues().build(); | |
private final Multimap<Class<?>, Consumer<?>> exitNodeListeners = MultimapBuilder.linkedHashKeys().arrayListValues().build(); |
This file contains 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 boto3 | |
region = 'us-east-1' | |
def find_instance_ids(ec2): | |
response = ec2.describe_instances(Filters=[ | |
{'Name': "tag:StopOffHours", 'Values': ["yes"]} | |
]) | |
return [ | |
instance['InstanceId'] | |
for reservation in response['Reservations'] |
This file contains 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
unless self.class.const_defined?('SCHEDULER') | |
SCHEDULER = Rufus::Scheduler.new(:lockfile => ".rufus-scheduler.lock") | |
unless SCHEDULER.down? | |
SCHEDULER.every('60s', :first_in => '10s') do | |
active_count = DASHBOARD.find_recent_users(10.minutes.ago).count() | |
# Rails.logger.info "======== active users #{active_count}" | |
Librato.measure('users.active', active_count) | |
end | |
SCHEDULER.every('60s', :first_in => '10s') do |
This file contains 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
ENV['GOOGLE_APPLICATION_CREDENTIALS'] = "#{ENV['HOME']}/google-service-account.json" | |
scopes = ['https://www.googleapis.com/auth/drive'] | |
drive = Google::Apis::DriveV2::DriveService.new | |
auth_client = Google::Auth.get_application_default(scopes).dup | |
auth_client.sub = 'user@mydomain.com' | |
drive.authorization = auth_client | |
report_folders = drive.list_files(q: "title = 'Reports'") | |
raise "Expected 1 folder called 'Reports', found #{report_folders.items.count}" if report_folders.items.count != 1 | |
parent_id = report_folders.items[0] |
This file contains 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
angular.module('myapp.directive.blacklist', []). | |
directive('maBlacklist', [ | |
function() { | |
return { | |
restrict: 'A', | |
require: 'ngModel', | |
scope: {'blacklist':'=gsBlacklist'}, | |
link: function($scope, $elem, $attrs, modelCtrl) { | |
var check = function(value) { |
This file contains 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
port=8080 | |
max_tries=10 | |
seconds_to_wait=3 | |
echo "Waiting for traffic on port $port to stop..." | |
for (( tries=1; tries<=$max_tries; tries++ )); do | |
# Netstat invocation tested on Ubuntu. Check your distro for differences. | |
connections=$(netstat -ant | grep ":$port.*:.*ESTABLISHED" | wc -l) | |
echo " $connections connections remaining. Try $tries/$max_tries." | |
if [ $connections -eq 0 ]; then | |
exit 0 |
This file contains 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
package com.cadrlife; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class ShellSplitter { | |
public List<String> shellSplit(CharSequence string) { | |
List<String> tokens = new ArrayList<String>(); | |
boolean escaping = false; | |
char quoteChar = ' '; |
This file contains 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
sudo iptables -t nat -N hot-deploy | |
sudo iptables -t nat -A PREROUTING -j hot-deploy | |
# Enable first server | |
sudo iptables -t nat -A hot-deploy -p tcp --dport 80 -j REDIRECT --to-ports 8080 | |
# Enable second | |
sudo iptables -t nat -A hot-deploy -p tcp --dport 80 -j REDIRECT --to-ports 8081 && sudo iptables -t nat -D hot-deploy 1 | |
# Back to first |