Skip to content

Instantly share code, notes, and snippets.

@davisford
davisford / Setup MongoDB on localhost as Replica Set
Last active May 14, 2024 06:37
Setup MongoDB replica set on local host with only a single primary
Add the `replication` section to the mongod.conf file:
```
$cat /usr/local/etc/mongod.conf
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
engine: mmapv1
"Walking on water and developing software from a specification are easy if both are frozen."
- Edward V Berard
"Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter."
- Eric S. Raymond
"Talk is cheap. Show me the code."
- Linus Torvalds
"In God we trust. All others must bring data."
@v1mkss
v1mkss / JetBrains Activation.md
Last active May 14, 2024 06:33
JetBrains Activation

JetBrains Activation

  • No proxy for:
*.apache.org, *.github.com, *.github.io, *.githubusercontent.com, *.gitlab.com, *.google.com, *.gradle.org, *.jetbrains.space, *.maven.org, cache-redirector.jetbrains.com, cloudconfig.jetbrains.com, download-cdn.jetbrains.com, download.jetbrains.com, downloads.marketplace.jetbrains.com, ea-report.jetbrains.com, github.com, gitlab.com, google.com, gradle.org, jcenter.bintray.com, plugins.jetbrains.com, resources.jetbrains.com, www.jetbrains.com

Activation Key:

UX394X3HLT-eyJsaWNlbnNlSWQiOiJVWDM5NFgzSExUIiwibGljZW5zZWVOYW1lIjoiSG9uZ2lrIFVuaXZlcnNpdHntmY3snbXrjIDtlZnqtZAiLCJsaWNlbnNlZVR5cGUiOiJDTEFTU1JPT00iLCJhc3NpZ25lZU5hbWUiOiLkvJfliJvkupEg5bel5L2c5a6kIiwiYXNzaWduZWVFbWFpbCI6ImhhbmF6YXdhbWl0b0BnbWFpbC5jb20iLCJsaWNlbnNlUmVzdHJpY3Rpb24iOiJGb3IgZWR1Y2F0aW9uYWwgdXNlIG9ubHkiLCJjaGVja0NvbmN1cnJlbnRVc2UiOmZhbHNlLCJwcm9kdWN0cyI6W3siY29kZSI6IkdPIiwicGFpZFVwVG8iOiIyMDI0LTEyLTEzIiwiZXh0ZW5kZ
@niravmsoni
niravmsoni / azureAppInsights_requests_dependencies
Created May 14, 2024 06:30
Azure Application insights - Linking requests and dependencies table
For linking `requests` with `dependencies` table, join using requests.id and dependencies.operationParentId
```kql
requests
|where timestamp > start_time and timestamp < end_time
| join (dependencies
| where ['type'] == "SQL" and data has "some-field-name-here"
) on $left.id == $right.operationParentId
```
@rushilgupta
rushilgupta / GoConcurrency.md
Last active May 14, 2024 06:30
Concurrency in golang and a mini Load-balancer

INTRO

Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".

Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).

Let's dig in:

Goroutines

@ctlllll
ctlllll / longest_chinese_tokens_gpt4o.py
Created May 13, 2024 19:53
Longest Chinese tokens in gpt4o
import tiktoken
import langdetect
T = tiktoken.get_encoding("o200k_base")
length_dict = {}
for i in range(T.n_vocab):
try:
length_dict[i] = len(T.decode([i]))
except:
@sundowndev
sundowndev / GoogleDorking.md
Last active May 14, 2024 06:29
Google dork cheatsheet

Google dork cheatsheet

Search filters

Filter Description Example
allintext Searches for occurrences of all the keywords given. allintext:"keyword"
intext Searches for the occurrences of keywords all at once or one at a time. intext:"keyword"
inurl Searches for a URL matching one of the keywords. inurl:"keyword"
allinurl Searches for a URL matching all the keywords in the query. allinurl:"keyword"
intitle Searches for occurrences of keywords in title all or one. intitle:"keyword"
import { Client } from "@upstash/qstash"
import { NextRequest } from "next/server"
const baseUrl = process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL
? `https://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`
: "http://localhost:3000"
interface Step<I> {
create: <O>(action: (prevResult: Awaited<I>) => O) => Step<O>
finally: (action: (prevResult: Awaited<I>) => any) => any

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@andrew--grant
andrew--grant / index.html
Created September 7, 2016 06:39
multiple items per slide in bootstrap carousel
<div class="container">
<h1>Use Bootstrap's carousel to show multiple items per slide.</h1>
<div class="row">
<div class="col-md-12">
<div class="carousel slide multi-item-carousel" id="theCarousel">
<div class="carousel-inner">
<div class="item active">
<div class="col-xs-4"><a href="#1"><img src="http://placehold.it/300/f44336/000000" class="img-responsive"></a></div>
</div>
<div class="item">