Skip to content

Instantly share code, notes, and snippets.

View farkaskid's full-sized avatar

Siddharth Shishulkar farkaskid

View GitHub Profile
@farkaskid
farkaskid / create_namespace_in_KV.txt
Last active January 10, 2020 06:42
Create namespace in KV
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces" \
-X POST \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY" \
-H "Content-Type: application/json" \
--data '{"title": "Requests"}'
The above HTTP request will create a namespace by the name Requests. The response should look something like this:
{
"result": {
"id": "30b52f55aafb41d88546d01d5f69440a",
@farkaskid
farkaskid / country_req_count_app_logic.js
Created January 8, 2020 07:56
Country request count app logic
const fetch = require('node-fetch')
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Fetch and log a request
* @param {Request} request
*/
@farkaskid
farkaskid / read_key_from_kv.txt
Created January 8, 2020 07:52
Read key from KV
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces/$NAMESPACE_ID/values/first-key" \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY" \
@farkaskid
farkaskid / write_data_KV.txt
Created January 8, 2020 07:51
Write data in KV
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/storage/kv/namespaces/$NAMESPACE_ID/values/first-key" \
-X PUT \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_AUTH_KEY" \
--data 'My first value!'
@farkaskid
farkaskid / adding_worker_listener_example.js
Created January 8, 2020 07:37
Example code for adding a listener to a worker
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
return new Response("hello world")
}
@farkaskid
farkaskid / goroutineExample.go
Last active April 5, 2019 14:26
Goroutine example.
// This function performs the given task concurrently by spawing a goroutine
// for each of those tasks.
func performAsyncTasks(task []Task) {
for _, task := range tasks {
// This will spawn a separate goroutine to carry out this task.
// This call is non-blocking
go task.Execute()
}
}
@farkaskid
farkaskid / client.go
Created March 25, 2019 09:38
Import example
package main
import (
"encoding/binary"
"bytes"
"log"
"os/exec"
"github.com/xlab/pocketsphinx-go/sphinx"
pulse "github.com/mesilliac/pulse-simple" // pulse-simple
@farkaskid
farkaskid / executor.go
Created March 25, 2019 09:35
Task executor example
package executor
import (
"log"
"sync/atomic"
)
// The Executor struct is the main executor for tasks.
// 'maxWorkers' represents the maximum number of simultaneous goroutines.
// 'ActiveWorkers' tells the number of active goroutines spawned by the Executor at given time.
@farkaskid
farkaskid / serviceDefinition.proto
Created March 13, 2019 06:01
A typical gRPC service definition
service HelloService {
rpc SayHello (HelloRequest) returns (HelloResponse);
}
message HelloRequest {
string greeting = 1;
}
message HelloResponse {
string reply = 1;
@farkaskid
farkaskid / protobufExample.proto
Created March 13, 2019 05:59
Typical Protobuf example
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}