Skip to content

Instantly share code, notes, and snippets.

View dyaa's full-sized avatar

Dyaa dyaa

View GitHub Profile
@dyaa
dyaa / index.js
Created December 28, 2017 16:33
Update Namecheap Dynamic DNS using No-IP
var lookup = require('dns-lookup');
var fetch = require('node-fetch');
lookup('dyaa.ddns.net', function (err, address, family) {
fetch(`https://dynamicdns.park-your-domain.com/update?host=[HOST]&domain=[DOMAIN_NAME]&password=[PASSWORD]&ip=${address}`);
});
@dyaa
dyaa / Challenge.md
Created December 19, 2017 09:16 — forked from rewop/Challenge.md
Test task

Task

Implement a page with a multi-step form, where each step shows when you have completed the previous one. In other words, we're not looking for previous/next buttons, but the next step should appear automatically.

Steps

  1. Two checkboxes with labels A1 and A2. Both are unchecked by default. Next step is available after at least one of them is checked.
  2. Two toggle buttons with labels B1 and B2. One button untoggles another (same as radio buttons behavior). Both are inactive by default. Next step is available when any option has been chosen.
  3. Text field with button Check. When button is pressed a value of the field will be send. Next step is available if a response from API is fine.
  4. Selectbox with C1, C2, C3 options. It is empty by default. Next step is available when any option has been chosen.
@dyaa
dyaa / jquery.preload.js
Created October 18, 2017 16:18 — forked from mathiasbynens/jquery.preload.js
JavaScript preload() function
/*!
* $.preload() function for jQuery – http://mths.be/preload
* Preload images, CSS and JavaScript files without executing them
* Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/
* Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/
* Note that since this script relies on jQuery, the preloading process will not start until jQuery has finished loading.
*/
jQuery.preload = function(array) {
var length = array.length,
@dyaa
dyaa / inview.js
Created September 27, 2017 09:16
Check if a particular element is in view.
// Let me show approch without JQuery. Simple JS function:
function isVisible(elem) {
var coords = elem.getBoundingClientRect();
var topVisible = coords.top > 0 && coords.top < 0;
var bottomVisible = coords.bottom < shift && coords.bottom > 0;
return topVisible || bottomVisible;
}
// Short example how to use it:
@dyaa
dyaa / timeAgo.js
Created September 11, 2017 03:55
timeAgo.js
function timeAgo(dateInput) {
const templates = {
prefix: "",
suffix: " ago",
seconds: "less than a minute",
minute: "about a minute",
minutes: "%d minutes",
hour: "about an hour",
hours: "about %d hours",
@dyaa
dyaa / init.js
Created August 1, 2017 13:38
Mongoose OS init.js
load('api_config.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_net.js');
load('api_sys.js');
load('api_timer.js');
// Helper C function get_led_gpio_pin() in src/main.c returns built-in LED GPIO
// ffi() returns a callbale object for the specified C function.
// As parsing the signature has non-trivial overhead, it's a good practice to
@dyaa
dyaa / index.js
Created July 9, 2017 10:49
MQTT nodejs connect
var mqtt = require('mqtt');
var url = "mqtts://localhost";
var options = {
port: 8883,
clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8),
username: '',
password: '',
};

URLs into Indexed DB, via Service Workers

Let's say you're using Indexed DB for the offline data store for a catalog. One of the object stores contains product images. Wouldn't it be great if you could just have something like this in your catalog page?

<img src="indexeddb/database/store/id">
@dyaa
dyaa / favComp.vue
Created May 21, 2017 09:17
Favourite Button component for Vue JS
<template>
<button class="btn btn-sm btn-primary" v-on:click="togglefav" ><i v-bind:class="[is_fav ? 'fa-heart' : 'fa-heart-o', 'fa']" aria-hidden="true"></i></button>
</template>
<script>
export default {
props:['is_fav'],
methods:{
togglefav:function(){
this.$emit('togglefav',!this.is_fav);
let newKey = new Date().getTime();
let list = af.database.object(`/items/${newKey}`).set({ name: 'Test' });