Skip to content

Instantly share code, notes, and snippets.

View moshfeu's full-sized avatar
🇮🇱
Standing for

Mosh Feu moshfeu

🇮🇱
Standing for
View GitHub Profile
@moshfeu
moshfeu / index.html
Created September 1, 2019 05:40
Polling data from the server and show notification if there a new data
<button onclick="sendMessage('start')">Start Listen</button>
<button onclick="sendMessage('stop')">Stop Listen</button>
<script>
let se;
navigator.serviceWorker.register('/sw.js').then(data => {
se = data.active;
console.log('se ready!');
});
function sendMessage(message) {
if (!se) {
@moshfeu
moshfeu / index.html
Last active September 1, 2019 05:07
Show notification from the service worker
<button onclick="sendMessage('start')">Start Listen</button>
<button onclick="sendMessage('stop')">Stop Listen</button>
<button onclick="sendMessage('notification')">Send a Notification</button>
<script>
let se;
navigator.serviceWorker.register('/sw.js').then(data => {
se = data.active;
console.log('se ready!');
});
function sendMessage(message) {
@moshfeu
moshfeu / index.html
Created August 31, 2019 18:45
Start / Stop interval on Service Worker
<button onclick="sendMessage('start')">Start Listen</button>
<button onclick="sendMessage('stop')">Stop Listen</button>
<script>
let se;
const registration = navigator.serviceWorker.register('/sw.js').then(data => {
se = data.active;
console.log('ready');
});
function sendMessage(message) {
@moshfeu
moshfeu / index.html
Created August 30, 2019 15:50
Send data to the Service Worker
<button onclick="sendMessage()">Send message</button>
<script>
let se;
const registration = navigator.serviceWorker.register('/sw.js').then(data => {
se = data.active;
console.log('ready');
});
function sendMessage() {
@moshfeu
moshfeu / final-code.js
Created March 30, 2019 20:57
AJV + Jest - gits #7
const validateSecuredUrl = function (schema, uri) {
validateSecuredUrl.errors = [{keyword: 'secured', message: 'avatar url must be "https" schema', params: {keyword: 'secured'}}];
return uri.indexOf('https://') === 0;
};
ajv.addKeyword('securedUrl', {
validate: validateSecuredUrl,
errors: true
});
@moshfeu
moshfeu / use-custom-keyword.js
Created March 30, 2019 20:12
AJV + Jest - gits #6
const validateSecuredUrl = function (schema, uri) {
return uri.indexOf('https://') === 0;
};
ajv.addKeyword('securedUrl', {
validate: validateSecuredUrl,
errors: true
});
it(`should user's schema be valid`, () => {
@moshfeu
moshfeu / meaningful-message-custom-matcher.js
Last active December 26, 2019 17:30
AJV + Jest - gits #5
expect.extend({
toBeValid(isValid, errorMessage) {
return {
message: () => isValid ? '' : errorMessage,
pass: isValid
}
}
});
it(`should user's schema be valid`, () => {
@moshfeu
moshfeu / wrap-validation-with-it.js
Last active February 20, 2022 17:15
AJV + Jest - gits #4
it.only(`should user's schema be valid`, () => {
const schema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"fullname": {
"type": "string",
"minLength": 2
},
@moshfeu
moshfeu / basic-validation.js
Created March 30, 2019 19:18
AJV + Jest - gits #3
import users from './users.json';
const shema = {
"type": "array",
"items": {
"type": "object",
"properties": {
"fullname": {
"type": "string",
"minLength": 2
@moshfeu
moshfeu / schema.json
Created March 30, 2019 19:11
AJV + Jest - gits #2
{
"fullname": "your full name"
}