Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Gisela 0GiS0

🏠
Working from home
View GitHub Profile
@0GiS0
0GiS0 / default-parameters-es6.js
Created Jan 27, 2019
default parameters with EMACScript 6
View default-parameters-es6.js
function add(a = 5, b = 10) {
return a + b;
}
console.log(add()); //15
View arrow-function.js
var add = (a, b) => {
return a + b;
}
View async-and-await.js
const delay = seconds => {
return new Promise(
resolve => setTimeout(resolve, seconds * 1000)
)
};
const counter = async() => {
await delay(1);
console.log('one second');
await delay(1);
@0GiS0
0GiS0 / fetch-and-async.js
Created Jan 27, 2019
Fetch and async working together
View fetch-and-async.js
const repos = async(loginName) => {
try {
var response = await fetch(`https://api.github.com/users/${loginName}/repos`);
var json = await response.json();
var followerList = json.map(repo => repo.name);
console.log(followerList);
} catch (error) {
console.log(`Error: ${error}`);
}
@0GiS0
0GiS0 / regular-function.js
Last active Jan 27, 2019
Regular function
View regular-function.js
function add(a, b) {
return a + b;
}
//or
var add = function(a,b){
return a + b;
}
View generator-function.js
function* hello() {
yield 'Hello Gisela';
yield 'Hello Alicia';
yield 'Hello Bea';
}
var helloInstance = hello();
console.log(helloInstance.next());
console.log(helloInstance.next());
console.log(helloInstance.next());
View HelloAzureController.php
<?php
// src/Controller/HelloAzureController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HelloAzureController
{
/**
View symfony-web.config
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="BlockAccessToPublic" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="/public/*" />
</conditions>
View chuck-norris-XMLHttpRequest-sample.js
const ChuckNorrisFact = () => {
return new Promise((resolves, rejects) => {
const api = 'https://api.chucknorris.io/jokes/random';
const request = new XMLHttpRequest();
request.open('GET', api);
request.onload = () => {
if (request.status === 200) {
resolves(JSON.parse(request.response));
} else {
rejects(new Error(request.response));
View chuck-norris-fetch-example.js
fetch('https://api.chucknorris.io/jokes/random')
.then(res => res.json())
.then(console.log);