Skip to content

Instantly share code, notes, and snippets.

@jaguilar
jaguilar / gist:5093046
Created March 5, 2013 18:52
Pathfinder tools
function CLAMP(min, max, n) {
if (n < min) return min;
if (n > max) return max;
return n;
}
function MEETPROB(n) {
return CLAMP(0.05, 0.95, 1-((n-1)/20.0));
}
hedgemony = (input) ->
lines = input.match(/[^\r\n]+/g);
numTests = parseInt(lines[0])
formatOutput i, solve lines[2*i] for i in [1..numTests]
solve = (line) ->
heights = (parseFloat s for s in line.split(" "))
n = 1
while n < heights.length - 1
average = (heights[n-1] + heights[n+1]) / 2.0
@jaguilar
jaguilar / gist:5479988
Last active May 24, 2017 06:55
So you think you know C++ #1
// Today we learn about the insane things that can be done with variadic templates.
template <int N> struct A {
template <typename O, typename R, typename... FArgs, typename... TArgs, typename... Args>
R operator()(O* o, R (O::*f)(FArgs...), const std::tuple<TArgs...>& t, Args... args) {
return A<N-1>()(o, f, t, std::get<N>(t), args...);
}
};
template <> struct A<-1> {
@jaguilar
jaguilar / gist:5533466
Created May 7, 2013 15:22
Clang format on save in sublime text 3
import sublime, sublime_plugin
import subprocess
class ClangFormatCommand(sublime_plugin.TextCommand):
def run(self, edit):
r = sublime.Region(0, self.view.size())
try:
p = subprocess.Popen(
['clang-format', '--style', 'Google'],
stdin=subprocess.PIPE,
@jaguilar
jaguilar / gist:5624553
Created May 22, 2013 01:12
Things I don't understand about rust part 2
// Why does this work . . .
trait Additive: Add<Self, Self> {}
fn sum<T, U: Zero + Additive>(seq: &[T], f: &fn(&T) -> U) -> U {
let mut u: U = Zero::zero();
for seq.each |x| { u += f(x); };
u
}
@jaguilar
jaguilar / gist:6657055
Last active December 23, 2015 15:39
Google docs script for scraping eve data from eve-central.com
// I hereby release this code to the public domain.
// Substitutes for placeholders in a string.
// Ex. sub("I am a {0} monkey.", "silly") -> "I am a silly monkey."
function sub(s) {
var args = arguments;
return s.replace(/{(\d+)}/g, function(match, number) {
var n = parseInt(number);
return typeof args[n+1] != 'undefined'
? args[n+1]
template <template <typename ...> class Container,
typename F,
typename InType,
typename OutType =
typename std::result_of<F(InType)>::type>
Container<OutType> c_transform(const Container<InType>& in,
const F& f) {
Container<OutType> out;
auto it = std::inserter(out, out.end());
for (const auto& e : in) {
@jaguilar
jaguilar / gist:b1adcab44b6868a9be4a
Last active August 29, 2015 14:10
Hayes (Grandma Aguilar) Family Stuffing
Ingredients:
3-4 cups of coarse bread crumbles (best made using stale bread that's been left out for 1/2 week)
2 cups chopped onion
1 cup finely chopped celery
1lb cheap, high-fat sausage meat -- think Jimmy Dean breakfast sausage
1-2 cups chicken broth
1/2-1 stick of butter
1 1/2 tsp sage
1/2 tsp thyme
@jaguilar
jaguilar / README.md
Last active February 25, 2024 16:18
bitburner: early-mid hacking setup

Problem Statement

  • Allocate resources from one server to work on another.
  • Weaken and grow first, before beginning to hack.
  • Allocate resources toward the most efficient available task, subject to some allowances for early progression.
  • Minimize RAM usage (scheduling overhead of around 30GB).

Overview

I designed a system with three main components:

import {getHosts, getAllHosts, schedule} from "hack-dist.js";
const target = args[0];
const numBatchWeaken = 9;
const numBatchGrow = 9;
const numBatchHack = 3;
export const allowedRam = 1000;
function killAllMatching(...args) {
getAllHosts().forEach(h => {