Bel LaPointe 2023-04-12 07:45:48 -06:00
commit a54d7537e1
3 changed files with 165 additions and 23 deletions

86
main.go
View File

@ -9,6 +9,8 @@ import (
"log"
"math/rand"
"net/http"
"strconv"
"strings"
"time"
"golang.org/x/time/rate"
@ -29,29 +31,67 @@ func main() {
}
links := bytes.Split(b, []byte{'\n'})
log.Print(port)
limiter := rate.NewLimiter(1, 1)
if err := http.ListenAndServe(fmt.Sprintf(":%d", port), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
limiter.Wait(r.Context())
link := ""
for len(link) == 0 {
link = string(links[rand.Intn(len(links))])
}
if proxy {
resp, err := http.Get(link)
if err != nil {
http.Error(w, err.Error(), http.StatusBadGateway)
}
for k, v := range resp.Header {
for _, v2 := range v {
w.Header().Add(k, v2)
}
}
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
} else {
http.Redirect(w, r, link, http.StatusTemporaryRedirect)
}
})); err != nil {
server := Server{
limiter: rate.NewLimiter(1, 1),
links: links,
proxy: proxy,
}
if err := http.ListenAndServe(fmt.Sprintf(":%d", port), server); err != nil {
panic(err)
}
}
type Server struct {
limiter *rate.Limiter
proxy bool
links [][]byte
}
func (server Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s := r.URL.Query().Get("n")
if s == "" {
s = "1"
}
n, err := strconv.Atoi(s)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
links := make([]string, n)
for i := range links {
link := ""
for len(link) == 0 || strings.Contains(fmt.Sprint(links), link) {
link = string(server.links[rand.Intn(len(server.links))])
}
links[i] = link
}
for _, link := range links {
if strings.HasPrefix(link, "http") {
server.serveHTTP(w, r, link)
} else if strings.HasPrefix(link, "literal://") {
w.Write([]byte(strings.TrimPrefix(link, "literal://")))
}
w.Write([]byte("\n"))
}
}
func (server Server) serveHTTP(w http.ResponseWriter, r *http.Request, link string) {
if server.proxy {
server.limiter.Wait(r.Context())
resp, err := http.Get(link)
if err != nil {
http.Error(w, err.Error(), http.StatusBadGateway)
}
for k, v := range resp.Header {
for _, v2 := range v {
w.Header().Add(k, v2)
}
}
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
} else {
http.Redirect(w, r, link, http.StatusTemporaryRedirect)
}
}

2
testdata/literal vendored Normal file
View File

@ -0,0 +1,2 @@
literal://hello world
literal://foo bar

100
testdata/rand-100.txt vendored Normal file
View File

@ -0,0 +1,100 @@
literal://“Focus on what you control.” — Its unhelpful to dwell on things outside of your control.
literal://“This too shall pass.” — “There are more things likely to frighten us than there are to crush us; we suffer more often in imagination than in reality.” Seneca
literal://“Not wanting something is as good as having it.” — If you dont want something, youre just as satisfied as someone who has it. Naval Ravikant says that “…desire is a contract that you make with yourself to be unhappy until you get what you want.”
literal://“Perfect is a myth. Make a choice.” — Start and iterate.
literal://“Use models.” — Dont recreate the wheel. Learn from others and save time.
literal://“Start super simple.” — Make the simplest version first. Dont complicate things. Build an MVP. Or a concierge MVP.
literal://“Read and listen to whatever youre most interested in.” — We get more out of what interests us. Find something that you enjoy reading instead of struggling through books. This idea came from Shane Parrish.
literal://“The best returns in life come from compound interest.” — This applies to relationships, habits and business. Thanks again Naval.
literal://“Successful people say no to almost everything.” — Focus.
literal://“Get it working by any means.” — Inspired by test-driven development. Improve the solution after the test passes. This applies to more than code.
literal://“Hire/build when it hurts.” — Handle your most painful problems first. Avoid premature optimization.
literal://“Set goals. And work backwards.” — Use big goals and small goals. Milestones can expose whether you undershot or overshot.
literal://“Dont read/watch the news. Skewed incentives.” — The news is a war on our attention. We are frightened into coming back to find out what else to be afraid of. This leads to availability bias and pessimism. Some of us are more afraid to fly than drive. Counteract the news with positive propaganda.
literal://“Youre the average of the 5 people you surround yourself with.” — This goes beyond people. What books, podcasts, videos or music do you consume?
literal://“Stay away from negative people.” — Vibes are contagious.
literal://“Listen to your gut.” — Dont ignore your instincts.
literal://“Hard choices, easy life. Easy choices, hard life.” — Hard decisions are often the most important. Ben Horowitz tells us to run towards the fear.
literal://“Consensus is regression to the mean.” — Trying to appease everyone takes you nowhere.
literal://“Think probabilistically.” — Think grey. Not black and white. This comes from Annie Duke and her book, Thinking in Bets. Assign percentages to your beliefs instead of speaking in absolutes.
literal://“Short engagements. Test situations.” — Test partnerships and commitments with trial runs. Build a small project together before going all in.
literal://“Red team. Blue team.” — Approach decisions as a critic and a supporter. Answers often reveal themselves.
literal://“IDK = No” — If youre uncertain, the answer should probably be no. This comes from Derek Sivers who wrote No “yes.” Either “HELL YEAH!” or “no.”
literal://“Know your alternatives.” — You always have a choice. Remain aware of your alternatives. Has your current path become too expensive? Has a better option emerged?
literal://“Dont risk ruin. Not even a small chance.” — This is what killed Long-Term Capital Management. When Genius Failed tells the story.
literal://“Use simple language. Few syllables. Short sentences. Short paragraphs.” — Simplicity is hard to achieve. Work hard so your audience doesnt have to.
literal://“Our brains are built to enjoy stories.” — Stories help information stick.
literal://“Were all driven by the fundamental desire to be appreciated”. — Dont underestimate the role of emotion.
literal://“Dont argue. Bet.” — Test belief through sacrifice not words.
literal://“Appeal to interest, not reason.” — We dont care about what makes sense. We care about what makes sense for us.
literal://“Misery loves company.” — So does happiness.
literal://“Happy people rarely become haters.” — Unconstructive critics are often dealing with their own demons.
literal://“Difficulty reveals character.” — Our masks fall during struggle. Build friendships through shared struggle. Jiu-Jitsu, hackathons, work, travel.
literal://“We stereotype all of the time. Rightly or wrongly. Dont ignore it. Signals matter.” — We take mental shortcuts to conserve energy. Use pattern interrupts when youre being negatively stereotyped. Life is short. Not fair.
literal://“The more you understand incentives, the less you take things personally.” — Incentives drive behavior. Sometimes its not personal. Change incentives instead of trying to change people.
literal://“Hurt people, hurt people.” — Dont react. Remember this.
literal://“Dont try to change someones worldview. Take those who see it and take them further.” — Its hard to change someones worldview. Its easier to help someone who already sees it. Whats the best use of your time?
literal://“Trust saves time.” — Invest in trust on the frontend and reap rewards on the backend. High trust relationships move faster and get more done.
literal://“Focus on compounding relationships.” — Focus on building relationships with long-term potential.
literal://“Dont force relationships.” — Whats forced eventually falls apart. Forcing only delays the inevitable.
literal://“Whoever cares less wins negotiations.” — Who can afford to walk away? Who needs it the least? This person tends to get the best deal.
literal://“Negotiation and business are about alternatives.” — Good decisions are relative. Its about choosing the best option among alternatives. Know your BATNA.
literal://“Its easier to resist in the beginning than the end.” — Mistakes become harder to correct the longer they linger. Sunk costs play tricks on us. Suck it up and rip the bandaid off now. Toxic relationships, bad hires and tough conversations. Its immediate pain versus chronic pain.
literal://“To know all is to forgive all.” — You would be more understanding if you knew everything about a person. Look closer when something doesnt make sense.
literal://“Focus on doing the thing, not the outcome.” — Commit to the process, not the outcome. You control whether you do it, not how it turns out.
literal://“Continuous improvement requires feedback.” — Feedback is a gift. No feedback. No improvement.
literal://“How to build confidence? Do things just outside your comfort zone. And repeat as it expands.” — This fuses confidence with progressive overload. Confidence-building can become a habit. This comes from Tim Ferriss.
literal://“If you decide to only do what works. Youre leaving a lot of opportunity on the table.” — Experiment.
literal://“Courage is a muscle that you need to train.” — Picture courage as a muscle that atrophies if it goes unused. Courage can also be strengthened through progressive overload. This came from a conversation with Harry Dry.
literal://“New things scare us. Do it anyway.” — By acknowledging fear, we are better able to move past it.
literal://“The biggest upside comes from being outside your comfort zone.” — In the words of DJ Khaled, major 🔑 alert. There will be an entire post on this.
literal://“Fear is a good thing. It means youre close to making a breakthrough.” — Fear can indicate potential growth opportunities.
literal://“Trying to appeal to all leads to average.” — We make too many concessions by trying to appeal to everyone. Seth Godin writes about the importance of being important to a small group. This rule mirrors “Consensus is regression to the mean.” But as David Senra says, repetition is persuasive.
literal://“Brevity is the soul of wit.” — Shorter is better.
literal://“Keep it simple.” — Stay away from unnecessary complexity. “Everything should be made as simple as possible, but not simpler.” -Einstein
literal://“Make it work. THEN make it pretty.” — Its easier to find an elegant solution once you have something working. This applies to any craft.
literal://“Dont make them think.” — Make it obvious.
literal://“Start with problems. Not solutions.” — Start by studying the problem instead of offering solutions. Study the lock before you make a key.
literal://“Frustration is an opportunity.” — Keep an idea journal. Jot down your problems. Some are business opportunities.
literal://“The most important part of business is the market. Its easier to ride a wave than it is to make one.” — A good team wont survive a bad market. A good product wont survive a bad market. A bad team with a bad product can survive in a good market. Pick hungry markets. This comes from Marc Andreessen who wrote The Only Thing That Matters.
literal://“Business opportunities can lead to others.” — Build something even if you dont have a “good” idea yet. We find new problems by solving problems.
literal://“A company can be your vehicle for continuous learning.” — Do something. Dont just study.
literal://“Awareness → Interest → Decision → Action” — Marketing is about awareness and conversion. Be visible. Pieter Levels, Andrey Azimov and Danielle Johnson are great examples of this.
literal://“50% Rule. 1/2 Growth. 1/2 Product.” — Spend half of your time talking to customers and half building. Dont endlessly build without feedback.
literal://“Does the business have network effects? Does it require funding?” — Network effects determine the number and size of the businesses a market. These are winner take most games. Nextdoor, LinkedIn, Facebook. Building these companies often involves raising money. Is this the kind of business that you want to run? Consider founder-market fit.
literal://“The more you ship. The more you increase your chance of success. Throw enough against the wall and somethings bound to stick.” —Andrew Pierno wrote about this in The Edison Approach to Profitability.
literal://“Consider buying a business. A statistically profitable approach.” — Validating business ideas involves a lot of false starts. Buying a business with product-market fit can be a statistically profitable approach. Price affects risk. Nassim Nicholas Taleb discussed the idea of statistical profitability in Fooled by Randomness.
literal://“Copy businesses that are working. These are formulas. Steal and improve them.” — Find a proven market. Study the problem. Be different or better or both.
literal://“Choose the fastest option. Refactor later.” — Prioritize speed early on. If youre unable to validate an idea, there may be no long-term to worry about.
literal://“Theory of 3 (good money) and 7 (wealth).” — Pick something that you can stick with for the long run. The hosts of The TMBA Podcast have a theory that it takes three years of working on something to make good money and seven years to generate wealth.
literal://“Build what YOU need or want.” — Sahil Lavingia says that if you build for yourself then you at least have one customer. It doesnt guarantee that others will want your solution but its a good start.
literal://“Ask for feedback to sell.” — If you want money, ask for advice. If you want advice, ask for money.
literal://“Dont try to sell what you wouldnt buy.” — Confidence is palpable. Potential customers will know if you believe in what youre selling.
literal://“Deliver value and build trust before you try to sell.” — Trust saves time. Write great content. Offer a free trial.
literal://“Have a rejection goal.” — Each no moves you closer to your goal. Flip the psychology of selling. Carl Jacobi told us to “Invert. Always invert.”
literal://“Start with why. Theyll be more likely to comply.” — Explain why something is important before making a request.
literal://“If you dont HAVE to keep reading or listening, dont.” — Dont trudge through books, podcasts or movies. Pick something else up. You dont have to finish every book.
literal://“The journey is the reward. Hedonistic adaptation.” — Lottery winners return to their baseline happiness levels. Learn to love the process. Thats where 99% of your time is spent.
literal://“We get more out of what interests us.” — You learn more when youre engaged. Charlie Munger says follow your natural drift.
literal://“Memento Mori.” — Your time is limited. Live with urgency. Remember death.
literal://“Dont self-reject.” — Dont tell yourself no before someone else can. This came from Sahil Lavingia.
literal://“Knowledge is (potential) power. Action makes it so.” — Applied knowledge is power. It takes courage and energy to activate. Derek Sivers said that if information was the answer, then wed all be billionaires with perfect abs.
literal://“Play long-term games. Compound returns.” — Focus on the long-term. Most benefits come from later stages of compounding. Pick up habits that you can see yourself sticking with. Jeff Bezos says to focus on what doesnt change.
literal://“Play asymmetric games. Life is not baseball. 1 hit can pay for 1000 runs.” — Some activities have asymmetric upside. Reading, writing, coding, selling, leading, comfort challenges, publishing. Play games with asymmetric upside.
literal://“Ask for what you want. You cant get what you dont ask for.” — Youll get a yes or a know.
literal://“Move with intent. Youre more likely to get what you want.” — Are you living proactively or reactively? Establish a north star to orient your decisions around. If you dont know what you want, you end up with a lot that you dont. Chuck Palahnuik
literal://“We thrive in niches. Specialize.” — Focus on what youre good at and rely on others for the rest. Leverage the API instead of building from scratch.
literal://“Wealth is made in extreme concentration.” — Wealth is maintained through diversification but made in extreme concentration. Focus.
literal://“Price affects risk.” — If an experiment is cheap, just do it. The more the price goes up, the more you should reconsider.
literal://“Follow up.” — This can yield dividends.
literal://“Live below your means for freedom and options.” — Establish a margin of safety to take more risks. James Clear says that Your success depends on the risks you take. Your survival depends on the risks you avoid.
literal://“Dont be desperate.” — Desperation often results in bad deals.
literal://“Ship daily/weekly/monthly. Build your shipping muscle.” — Become comfortable exposing your art to an audience and embracing feedback.
literal://“Fuck imposter syndrome. Do it.” — We second-guess ourselves a lot. Do not wait for permission. It may never come. Acknowledge self-doubt and move past it.
literal://“Put your name on it. This makes you try harder. Accountability.” — You work harder when your name is on the line.
literal://“Get the incentives right.” — Its the most important thing in management. You get what you reward. Align incentives.
literal://“Associate growth with doing. Not reading/watching/listening.” — Dont overstudy and underexecute.
literal://“Do high energy tasks early in the day.” — Do creative work when you have the most energy.
literal://“Reading fiction = Increased empathy and creativity. Better verbal communication and writing. And less stress via escapism.” — I once avoided novels because I didnt know what I would learn. I still dont know. But I read fiction for other reasons.
literal://“Use podcasts to stay motivated.” — Listening to other misfits helps me stay motivated.
literal://“Habit levels. 3/10/30/100/300/1000/etc.” — The rule of 3 and 10. This came from an interview with Phil Libin in Tools of Titans. It states that everything changes at multiples of 3 and 10. When a company triples in size, everything breaks. I use multiples of 3 and 10 to celebrate milestones in habits and business. Gamify your life to stay engaged through the messy middle.