Skip to content

Instantly share code, notes, and snippets.

View athulmurali's full-sized avatar
🎯

Athul Muralidharan athulmurali

🎯
View GitHub Profile
@jeremiahlangner
jeremiahlangner / Observables.html
Last active January 23, 2019 21:36
Sticky JS issues, often used in code interviews. Use, memorize, steal from at your leisure.
<html>
<body>
<button id="add">+</button>
<span id="result">0</span>
<button id="subtract">-</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.3.3/rxjs.umd.min.js"></script>
<script>
/**
*
* Observables:
@fgilio
fgilio / axios-catch-error.js
Last active April 11, 2024 19:02
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@odewahn
odewahn / error-handling-with-fetch.md
Last active June 9, 2024 14:27
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
 })
@cpatrick
cpatrick / folder_upload_test.html
Created March 27, 2013 18:06
Simple test for folder uploading.
<html>
<head>
<title>HTML5 Folder Upload Test</title>
</head>
<body>
<div id="container">
<input type="file" id="file_input" name="file_input_folder[]"
multiple webkitdirectory="" mozdirectory="true" directory="" />
</div>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
@aspyct
aspyct / signal.c
Last active February 19, 2024 11:24
Unix signal handling example in C, SIGINT, SIGALRM, SIGHUP...
/**
* More info?
* a.dotreppe@aspyct.org
* http://aspyct.org
*
* Hope it helps :)
*/
#include <stdio.h>
#include <stdlib.h>