Skip to content

Instantly share code, notes, and snippets.

@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">
@snowcrumble
snowcrumble / Go 基于 Interface 的泛型.md
Created September 26, 2020 08:00
Go 基于 Interface 的泛型

Go 基于 Interface 的泛型

Go 泛型的草案截止今日已经基本定型了,与其他语言最大的不同应该就是 Go 的泛型利用 Interface 做 Constraint,可以说是与现有的 Interface 充分结合,之前的草案本来要引入新的关键字 contracts 在这次改动后被现有的 interface 代替,这使得 Interface 的概念更像 Rust 的 trait(实际上 Go 的泛型概念也与 Rust 相似),不过 Go 中实现 Interface 不需要显示声明,所以我想先谈一下 Interface 这个 Go 语言中最出色的“发明”。

Interface

Interface 实现了 Go 风格的 Duck typing。它实现的方法查表方式与其他语言有些不同,有方法的语言大概有两个阵营

  1. C++ 和 Java 在编译时生成方法的静态方法表,比如 C++ 的 vtable
  2. Js 和 Python 动态查询,并花式缓存
@umayr
umayr / recover-deleted-branch.sh
Created April 1, 2016 11:41
How to recover a deleted branch
## Pre-requisite: You have to know your last commit message from your deleted branch.
git reflog
# Search for message in the list
# a901eda HEAD@{18}: commit: <last commit message>
# Now you have two options, either checkout revision or HEAD
git checkout a901eda
# Or
git checkout HEAD@{18}
@IronWarrior
IronWarrior / UnityProjectJunctionTool.cs
Last active May 14, 2024 06:17
Unity editor tool to create dummy Unity projects to allow a single project to be open in multiple editor instances.
// gist by Roystan (IronWarrior): https://gist.github.com/IronWarrior/005f649e443bf51b656729231d0b8af4
// Video demo: https://twitter.com/DavigoGame/status/1300842800964018178
//
// CONTRIBUTIONS:
// Mac and Linux support added by Creature Coding: https://creaturecoding.com/
//
// PURPOSE:
// Unity does not permit a project to be open in two different editor instances.
// This can be frustrating when building projects with multiplayer networking,
// as it would require you to create a build every time you wish you test your netcode.