Skip to content

Instantly share code, notes, and snippets.

Avatar

Siddharth Shishulkar farkaskid

View GitHub Profile
@farkaskid
farkaskid / country_req_count_app_logic.js
Created Jan 8, 2020
Country request count app logic
View country_req_count_app_logic.js
const fetch = require('node-fetch')
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
/**
* Fetch and log a request
* @param {Request} request
*/
View read_key_from_kv.txt
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" \
View write_data_KV.txt
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 / create_namespace_in_KV.txt
Last active Jan 10, 2020
Create namespace in KV
View create_namespace_in_KV.txt
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 / adding_worker_listener_example.js
Created Jan 8, 2020
Example code for adding a listener to a worker
View adding_worker_listener_example.js
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
return new Response("hello world")
}
View client.go
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 Mar 25, 2019
Task executor example
View executor.go
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 Mar 13, 2019
A typical gRPC service definition
View serviceDefinition.proto
service HelloService {
rpc SayHello (HelloRequest) returns (HelloResponse);
}
message HelloRequest {
string greeting = 1;
}
message HelloResponse {
string reply = 1;
@farkaskid
farkaskid / protobufExample.proto
Created Mar 13, 2019
Typical Protobuf example
View protobufExample.proto
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
@farkaskid
farkaskid / goroutineExample.go
Last active Apr 5, 2019
Goroutine example.
View goroutineExample.go
// 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()
}
}
You can’t perform that action at this time.