Skip to content

Instantly share code, notes, and snippets.

View J-Cake's full-sized avatar
🥚
Egg

Jacob Schneider J-Cake

🥚
Egg
View GitHub Profile
@J-Cake
J-Cake / brightnessSlider.js
Last active January 14, 2019 05:16
My React-Native Drawing app, but without any interactivity
import React, {Component} from 'react';
import {View, Text, Dimensions} from 'react-native';
import styles from './styles.js';
import LinearGradient from 'react-native-linear-gradient';
import utils from './utils.js';
const d = Dimensions.get('window'),
width = d.width,
height = d.height;
export default class BrightnessSlider extends Component {
@J-Cake
J-Cake / Multi instance comms.js
Created January 16, 2019 13:01
How to only have one instance of a window open while feeding info into it.
let isMainWindow = false; // keep track of main instance.
// Of course the main instance should be kept track of in a better way than this, perhaps find a way of uniquely identifying the tabs
// and storing the ID of the active tab in localStorage.
window.addEventListener('load', e => {
if (!window.localStorage.mainWindowVacant) window.localStorage.mainWindowVacant = "true"; // initialsise window.localStorage
if (!window.localStorage.openInstances) window.localStorage.mainWindowVacant = "true"; // initialsise window.localStorage
if (window.localStorage.mainWindowVacant !== "false") {
@J-Cake
J-Cake / App.js
Last active February 8, 2019 00:47
import React from 'react';
import {Appbar, BottomNavigation, Provider as PaperProvider} from 'react-native-paper';
import {Provider, connect} from 'react-redux';
import {createStore} from 'redux';
import Theme from './styles/theme';
import Screens from './screens';
/*
{ key: 'Settings', title: 'Settings', icon: 'settings', color: Theme.colors.primary }, //, color: '#00796b'
@J-Cake
J-Cake / NN.js
Created February 15, 2019 07:05
Malfunctioning NN. I gave it my best shot at translating from python.
let weights = Array.from({
length: 3
}, () => Math.random() * 2 - 1)
// let weights = [-0.16595599, 0.44064899, -0.99977125]
let inputs = [
[0, 1, 1],
[1, 1, 1],
[1, 0, 1],
[0, 1, 1]
const that = this; // lol I know
const download = <DownloadComp onComplete={() => this.next()}
onStatusChange={async function (status) {
if (status !== 2 && status !== 3) {
console.log('unaffected');
} else {
console.log(this);
that.setState(prev => ({
@J-Cake
J-Cake / App.js
Created April 20, 2019 03:21
The React refs keep dissapearing
async beginDownload() {
if (this.state.downloadURL) {
const that = this; // lol I know
const onStatusChange = async function (status) {
if (status === 2 || status === 3) {
that.forceUpdate();
// this.props.remove.bind(this)();
}
};
@J-Cake
J-Cake / entry.cpp
Created May 19, 2019 11:52
A simplified demonstration of what I'm trying to achieve in C++
#include <store.h>
#include <iostream>
int main() {
cout << Store.name << endl;
Store.name = "Isaac";
cout << Store.name << endl;
}
@J-Cake
J-Cake / Track Download Progress in node.js
Created July 9, 2019 13:14
This script records progress made over download without using the `pipe` function and is incredibly memory efficient.
const http = require('http');
const fs = require('fs');
const path = require('path');
const fileLocation = path.join(__dirname, 'video.mp4');
fs.writeFileSync(fileLocation, '');
const file = fs.createWriteStream(fileLocation);
function printSize(bytes) {
const {exec} = require('child_process');
function spawn(...args) {
return new Promise(function (resolve, reject) {
const process = exec(`java -jar gp.jar --delete D27600008501 --key ${lockKey}`, function (err, stdout, stderr) {
if (err)
return reject(err);
});
process.on('exit', code => resolve(code));
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
:root {
--background: black;