Skip to content

Instantly share code, notes, and snippets.

View jurosh's full-sized avatar

Jurosh jurosh

View GitHub Profile
@jurosh
jurosh / Component.tsx
Created June 18, 2018 21:45
VSCode GRAPHQL integration - example
import * as React from 'react';
import gql from 'graphql-tag';
import { Query } from 'react-apollo';
import { GetSystemLogsQuery } from '../generated/schema';
const GET_SYSTEM_LOGS = gql`
query GetSystemLogs {
system {
logs // INTELISENSE NOT WORKING HERE :(
}
@jurosh
jurosh / middleware.js
Last active April 24, 2018 07:31
Redux Middleware: Simple local storage single item cache
const cacheMiddleware = store => next => action => {
if(action.type !== 'GET_SOMETHING') {
return next(action);
}
const data = getFromLocalstorage()
if(!data) {
// Fetch and put to localstorate for later use
const data = fetchFromServer()
return next({ type: 'SERVER_RESULT', data })
}
@jurosh
jurosh / relivedown.js
Last active December 2, 2021 03:58
Relive.cc video downloader
// Open BROWSER CONSOLE (F12) and place inside this content
// This will open source file...
// You need to save it manually with `ctrl + s`
(function openVideoFile() {
const downa = document.createElement('a');
downa.id = 'videofileClickme'
downa.href = document.querySelector("meta[property=\"og:video:secure_url\"]").content
downa.download = 'MyRide';
document.body.appendChild(downa)
videofileClickme.click();
@jurosh
jurosh / Component.jsx
Last active July 14, 2017 14:38
React map keys issue?
// https://stackoverflow.com/questions/42773892/wrong-components-rendered-by-preact
// https://facebook.github.io/react/docs/lists-and-keys.html
import * as React from 'react';
class Component extends React.Component<any, any> {
constructor() {
super();
this.state = { listing: ['First', 'Second', 'Last'] };
setInterval(() => {
@jurosh
jurosh / javascript-prototype-chain.js
Last active May 3, 2017 10:06
Trace Prototype Chain (See, explore JavaScript prototype chain)
function tracePrototypeChainOf(object) {
let proto = object.constructor.prototype;
let result = '';
while (proto) {
result += ' -> ' + proto.constructor.name;
proto = Object.getPrototypeOf(proto)
}
return result;
}
@jurosh
jurosh / RPi_I2C_driver.py
Created March 4, 2017 11:21 — forked from DenisFromHR/RPi_I2C_driver.py
RaspberryPi I2C LCD Python stuff
# -*- coding: utf-8 -*-
"""
Compiled, mashed and generally mutilated 2014-2015 by Denis Pleic
Made available under GNU GENERAL PUBLIC LICENSE
# Modified Python I2C library for Raspberry Pi
# as found on http://www.recantha.co.uk/blog/?p=4849
# Joined existing 'i2c_lib.py' and 'lcddriver.py' into a single library
# added bits and pieces from various sources
# By DenisFromHR (Denis Pleic)
@jurosh
jurosh / immutable.html
Last active February 8, 2017 21:12
JavaScript comparision array push, concat and destructed push ("fake immutable") in Chrome
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" /></head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.1/immutable.min.js"></script>
<script>
const TIMES = 10000;
window.onload = function(){
console.time('time');
let initial = Immutable.List.of();
@jurosh
jurosh / gist:1351508229deb061e81bb959a837b257
Created January 7, 2017 10:27
Swap 2 values in JavaScript (hacky way)
// http://stackoverflow.com/questions/16201656/how-to-swap-two-variables-in-javascript
a = b + (b = a, 0)
// (b=a, 0) sets b to the old value of a and yields 0
// a = b + 0 sets a to the old value of b
/**
* Check if request is secure (https)
* http://stackoverflow.com/questions/85816/how-can-i-force-users-to-access-my-page-over-https-instead-of-http
* @return bool
*/
function isRequestSecure() {
return (
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|| $_SERVER['SERVER_PORT'] == 443
|| (
@jurosh
jurosh / gist:7f984d421712909e44627c6e2c471fbe
Last active October 25, 2016 22:05
OPTIONS Preflight request | fetch
<html>
<body>
<script>
// Alternative fetch('http://biz.jurosh.local/packages/test.php', {headers: {'Content-Type': 'application/json'}})
fetch('http://biz.jurosh.local/packages/test.php', {method: 'PUT'})
.then(data => console.log('DATA!'));
// Accept is like: Here is my request and I would like (to Accept) this response format