Skip to content

Instantly share code, notes, and snippets.

View ypetya's full-sized avatar
💭
🚀

Peter Kiss ypetya

💭
🚀
  • Budapest, Hungary
View GitHub Profile
@ypetya
ypetya / gist:ecfcd09ed451b140ff9ee87c32df3da0
Created December 29, 2022 07:44 — forked from shinyquagsire23/gist:f7907fdf6b470200702e75a30135caf3
Philips Hue BLE Services and Characteristics (WIP)
DeviceInfo(softwareRevision, isOn,
SceneLightState(color, powerOnBehavior, deviceInfo
Light(id,
Capabilities(dimmable, customState
PowerOnBehavior(option
hueplay, huebloom, hueiris, huelightstrip, huego, plug, bollard, wallspot, groundspot, flexiblelamp, wallshade, walllantern
[ea:44:13:bd:db:59] Service [b8843add-0000-4aa1-8794-c3f462030bda] Unknown, ble_firmware_update?
[ea:44:13:bd:db:59] Characteristic [b8843add-0004-4aa1-8794-c3f462030bda]

Puncture

@ypetya
ypetya / deepProperty.js
Created November 12, 2019 15:44
access infinite deep properties - meta programming with Proxy Object - helpful for JSON parse
const endlessProxyHandler = {
get: (target, path) => {
if (path === 'value') {
return target.value;
} else if (path === 'array') {
return target.value || [];
}
let newTarget = {};
if (typeof target[path] === 'object' && target[path] !== null) {
@ypetya
ypetya / chart.js
Last active October 27, 2019 09:20
vadallomany
const
title = {height: 30, text: 'Vadállomány - Kilőtt vad [ezer db]'},
legend = {height: 50},
margin = {top: 20, right: 20, bottom: 30, left: 40},
bar = {marginRatio: 0.8, paddingRatio: 0.1},
width = document.body.clientWidth - margin.left - margin.right,
height = document.documentElement.clientHeight,
y = d3.scaleLinear().range([
height - margin.top - margin.bottom - legend.height - title.height, // the bottom
margin.top + margin.bottom + legend.height]), // the top
@ypetya
ypetya / makeInvertable
Created October 11, 2019 06:11
Invertable d3.axis
makeInvertable = (axis, t) => {
axis.invert = x => {
const domain = axis.domain(),
range = axis.range(),
invertScale = t ? t.domain(range).range(domain) :
d3.scaleQuantize().domain(range).range(domain);
return invertScale(x);
};
};
@ypetya
ypetya / gdp_world.csv
Last active October 27, 2019 09:19
GDP - 2019 ksh.hu d3.v5
We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 20 columns, instead of 16. in line 8.
country,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018
Ausztria,213.6,220.5,226.7,231.9,242.3,254.1,267.8,284.0,293.8,288.0,295.9,310.1,318.7,323.9,333.1,344.3,356.2,369.9,386.1
Belgium,258.2,265.8,275.1,282.6,298.7,311.5,326.7,344.7,354.1,348.8,365.1,379.1,387.5,392.3,400.1,411.1,424.6,439.2,450.5
Bulgária,14.3,15.8,17.3,18.7,20.9,23.9,27.2,32.4,37.2,37.3,38.2,41.3,41.9,41.9,42.8,45.3,48.1,51.7,55.2
Ciprus,10.8,11.6,12.1,12.9,13.9,15.0,16.3,17.6,19.0,18.7,19.3,19.7,19.5,18.1,17.6,17.7,18.5,19.6,20.7
Csehország,66.8,75.4,87.1,88.2,96.0,109.6,123.9,138.3,161.3,148.7,156.7,164.0,161.4,157.7,156.7,168.5,176.4,191.7,206.8
Dánia,178.0,184.0,189.8,193.4,202.4,212.8,225.5,233.4,241.6,231.3,243.2,247.9,254.6,258.7,265.8,273.0,282.1,292.8,297.6
Egyesült Királyság,1787.3,1816.2,1881.2,1809.1,1934.5,2030.9,2150.3,2252.5,1984.0,1725.4,1850.5,1894.9,2089.6,2074.0,2287.9,2611.9,2403.4,2338.0,2393.7
Észtország,6.2,7.0,7.8,8.7,9.7,11.3,13.5,16.2,16.5,14.1,14.7,16.7,17.9,18.9,20
@ypetya
ypetya / data.csv
Last active October 5, 2019 18:55 — forked from gencay/data.csv
stacked bar chart d3.v5
State Under 5 Years 5 to 13 Years 14 to 17 Years 18 to 24 Years 25 to 44 Years 45 to 64 Years 65 Years and Over
AL 310504 552339 259034 450818 1231572 1215966 641667
AK 52083 85640 42153 74257 198724 183159 50277
AZ 515910 828669 362642 601943 1804762 1523681 862573
AR 202070 343207 157204 264160 754420 727124 407205
CA 2704659 4499890 2159981 3853788 10604510 8819342 4114496
CO 358280 587154 261701 466194 1464939 1290094 511094
CT 211637 403658 196918 325110 916955 968967 478007
@ypetya
ypetya / toTimeZone.js
Created June 27, 2019 12:57
Time zone in js
/**
* @return json object with converted time parts
* */
toTimeZone(utcDate, timeZone) {
return new Intl.DateTimeFormat('default', {
timeZone,
hour: 'numeric', minute: 'numeric', year: 'numeric', month: 'numeric', day: 'numeric', hour12: false
})
.formatToParts(utcDate).reduce((acc, curr) => ({...acc, [curr.type]: curr.value}), {});
}
@ypetya
ypetya / registerValidSW.js
Created June 14, 2018 11:47
register valid service worker
function registerValidSW(swUrl) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
@ypetya
ypetya / chainProcess.js
Last active May 31, 2018 08:36
Simple functional chain process
const cp = require('child_process');
const execute = string => new Promise((resolve, reject)=>{
console.log(string);
cp.exec(string, (err, stdout, stderr) => {
if (err) {
reject(err);
}
const out = stdout.toString().trim();