Skip to content

Instantly share code, notes, and snippets.

@userbig
userbig / asyncio_loops.py
Created March 19, 2022 13:37 — forked from lars-tiede/asyncio_loops.py
asyncio + multithreading: one asyncio event loop per thread
import asyncio
import threading
import random
def thr(i):
# we need to create a new loop for the thread, and set it as the 'default'
# loop that will be returned by calls to asyncio.get_event_loop() from this
# thread.
loop = asyncio.new_event_loop()
@userbig
userbig / benchmark.js
Created April 8, 2021 06:38
POSTMAN BENCHMARK SCRIPT
url = "dummy.restapiexample.com/api/v1/employees";
//1000 ms is a maximum allowed value according to requirements
maximumResponseTime = 1000;
//100 is a number of sent requests according to requirements
iterations = 100;
//100 ms is a delay between requests according to requirements
delay = 100;
//responseTimes is an array for collecting response time values
@userbig
userbig / ImageTrait.php
Created November 10, 2020 15:14 — forked from mul14/ImageTrait.php
Easy to get image from a model - Laravel
<?php
namespace App;
use Gregwar\Image\Image;
use Symfony\Component\HttpFoundation\File\UploadedFile;
trait ImageTrait
{
protected $imageWidth, $imageHeight;
@userbig
userbig / share-urls.md
Created October 16, 2020 09:33 — forked from apisandipas/share-urls.md
Share url's for Facebook, Twitter, Pinterest and Linkedin with just get variables

Creating share buttons with just URL's

Twitter

http://twitter.com/share?text=<TITLE>&url=<URL>

E.g. http://twitter.com/share?text=This+is+google+a+search+engine&url=https%3A%2F%2Fwww.google.com

Facebook

http://www.facebook.com/sharer.php?u=&amp;p[title]=

@userbig
userbig / error-handling-with-fetch.md
Created October 15, 2020 07:47 — forked from odewahn/error-handling-with-fetch.md
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
@userbig
userbig / git-pull-all
Created July 2, 2020 18:58 — forked from grimzy/git-pull-all
Git pull all remote branches
#!/usr/bin/env bash
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
function AutoPXLS(images){
//
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
function AutoPXLS(images){
//
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
function AutoPXLS(images){
//
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...