Skip to content

Instantly share code, notes, and snippets.

View buttercubz's full-sized avatar
:octocat:
Fly

Erick Sosa Garcia buttercubz

:octocat:
Fly
View GitHub Profile
@sushruth
sushruth / pipeable.ts
Last active September 19, 2021 02:40
Type safe pipe operator equivalent
class Pipeable<I> {
constructor(public value: I) { }
public pipe<O>(fn: (input: I) => O) {
const output = fn(this.value);
return Object.assign(new Pipeable(output).pipe, {
value: output
});
}
}
@kt3k
kt3k / analyze-deps.ts
Last active July 2, 2021 05:37
Analyze deps of JavaScript/TypesScript
import { transform } from "https://esm.sh/sucrase";
import { init, parse } from "https://unpkg.com/[email protected]/dist/lexer.js";
(async () => {
await init;
const pathToAnalyze = "https://esm.sh/react";
const resp = await fetch(pathToAnalyze);
console.log("Analyzing", resp.url);
@timreichen
timreichen / Deno Module Style Guide.md
Last active April 17, 2022 18:59
Deno Module Style Guide
@cuixin
cuixin / json_to_map.go
Created October 25, 2017 01:53
json to map[string]interface{} example in golang
package main
import (
"encoding/json"
"fmt"
)
func dumpMap(space string, m map[string]interface{}) {
for k, v := range m {
if mv, ok := v.(map[string]interface{}); ok {
//ROUTER
//Silly small javascript router to help me learn how they worked in a very simple way
(function (){
const appDiv = "app";
// Both set of different routes and template generation functions
let routes = {};
let templates = {};
@jtsternberg
jtsternberg / colliding.js
Last active August 12, 2024 17:52 — forked from JayWood/colliding.js
Detect if two elements are colliding/overlapping
/**
* Detects if two elements are colliding
*
* Credit goes to BC on Stack Overflow, cleaned up a little bit
*
* @link http://stackoverflow.com/questions/5419134/how-to-detect-if-two-divs-touch-with-jquery
* @param $div1
* @param $div2
* @returns {boolean}
*/
WebSockets vs. Server-Sent events/EventSource
---------------------------------------------
Both WebSockets and Server-Sent Events are capable of pushing data to browsers. To me they seem to be competing technologies.
What is the difference between them? When would you choose one over the other?
Websockets and SSE (Server Sent Events) are both capable of pushing data to browsers, however they are not competing technologies.
Websockets connections can both send data to the browser and receive data from the browser.
A good example of an application that could use websockets is a chat application.
@mattetti
mattetti / multipart_upload.go
Last active March 22, 2025 23:09
Example of doing a multipart upload in Go (golang)
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"