Skip to content

Instantly share code, notes, and snippets.

View tofikhidayatxyz's full-sized avatar
🏠
Working With Cofee

Tofik Hidayat tofikhidayatxyz

🏠
Working With Cofee
View GitHub Profile
<?php
$file = file_get_contents('./products.json');
$json = json_decode($file, 1);
$param = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$param = $param == 0 ? 1: $param;
$per_page = 3;
$data = array_slice($json, ($param * $per_page) - $per_page , 3);
document.querySelectorAll('.btn-sharer').forEach((item)=>{
item.addEventListener('click',(event)=>{
let url = window.location.href;
let target = item.getAttribute('data-share');
let title = document.title;
let windowHeight = 350;
let windowWidth = 520;
let alignTop = (screen.height / 2) - (windowHeight / 2);
// post data
async function postData(url = '', data = {}) {
return new Promise(function(resolve, reject) {
fetch(url, {
method: 'POST',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json'
const exchange = (arr)=> {
let data = [];
arr.forEach((origin)=> {
let order = 1;
arr.forEach((target)=> {
if(target !== origin) {
order *= target;
}
'use strict';
const cacheName = 'static-cache-v1';
const files = [
//'/',
'/css/app.css',
];
const acceptFormat = ['.ico','.png','.jpg','.jpeg','.svg','.js','.css','.json'];
<title>Title name</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="FlipsFlopsTeam">
<meta property="og:locale" content="id_ID" />
<meta property="og:locale:alternate" content="en_GB" />
<meta property="og:site_name" content="" />
<meta property="og:url" content="">
<meta property="og:title" content="" />
// today
function today() {
let date = new Date();
return Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())
}
// tomorrow
function tomorrow() {
let date = new Date();
date.setDate(date.getDate() + 1);
return Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())
https://drive.google.com/file/d/1Zm-3067Y1p_OFD6G8jfXgPuiLsl6_qMI/view?usp=drivesdk
var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://';
var address = protocol + window.location.host +'/example/dumy';
var socket = new WebSocket(address);
socket.onopen = ()=> {
socket.send("try autoload !");
};
socket.onmessage = (msg)=>{
console.log(msg.data);
};
@tofikhidayatxyz
tofikhidayatxyz / dom.js
Created June 3, 2019 12:29
Trying use simple dom javascript
const $ = function(elem) {
return document.querySelectorAll(elem);
}
// object add event click
Object.prototype.click = function(event) {
return this.forEach(function(el) {
el.addEventListener("click",function() {
event()
})