Skip to content

Instantly share code, notes, and snippets.

View williamsiuhang's full-sized avatar

William Siuhang williamsiuhang

View GitHub Profile
@williamsiuhang
williamsiuhang / rn-gyroscope-parallax.js
Created July 9, 2020 20:41
React Native Image 3D Parallax using mobile gyroscope (Expo's DeviceMotion)
import React from 'react';
import { View, Animated, Easing } from 'react-native';
import { DeviceMotion } from 'expo-sensors';
class AnimatedAnalyticsImage extends React.Component {
state = {
motionX: 0,
motionY: 0,
motionZ: 0
@williamsiuhang
williamsiuhang / settings.json
Created May 17, 2020 05:20
VS Code default dark + theme modification
{
"workbench.preferredDarkColorTheme": "Seti Monokai",
"workbench.preferredHighContrastColorTheme": "Seti Monokai",
"window.zoomLevel": 0,
"workbench.colorCustomizations": {
"[Default Dark+]": {
"editor.background": "#161616",
"editorIndentGuide.background": "#2c2c2c",
"editor.selectionBackground": "#135564",
@williamsiuhang
williamsiuhang / react-three-scene.js
Created December 26, 2019 07:33
Simple React Three js scene component
import React from 'react';
import * as THREE from 'three';
import { TrackballControls } from 'three/examples/jsm/controls/TrackballControls.js';
class Scene extends React.Component {
constructor(props) {
super(props)
this.animate = this.animate.bind(this);
@williamsiuhang
williamsiuhang / .react-router-htaccess
Created October 15, 2019 18:11
Apache .htaccess to fix 404 issue with React Router client routing
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
@williamsiuhang
williamsiuhang / exclude-darktheme
Created May 23, 2019 14:46
Terminal commands to exclude Mac apps from Dark Theme
// get app bundle id
osascript -e 'id of app "Calendar"'
// update theme | com.apple.iCal is App's bundle identifier
defaults write com.apple.iCal NSRequiresAquaSystemAppearance -bool yes
@williamsiuhang
williamsiuhang / gcloud-storage-upload.js
Last active May 10, 2019 17:43
Uploading an image/jpeg into Google Cloud Storage w/ POST method
// Upload image using http POST & Google Cloud Storage API
var uploadUrl = 'https://www.googleapis.com/upload/storage/v1/b/wkndevents/o?uploadType=media&name=loremipsum.jpg'; // upload with direct HTTP call
var tmp_auth = 'Bearer tokenhere123'; // Get Bearer Access token here - https://developers.google.com/oauthplayground
// Enable access for Cloud Storage v1 & Cloud Storage JSON API
var fileinput = $('.file-upload-input')[0]; // <input type='file'>
var file = fileinput.files[0]; // just support 1st file for now
// post image into google cloud storage
@williamsiuhang
williamsiuhang / react-state-props-onupdate.js
Created April 28, 2019 00:31
Method to determine if state or prop is updated
componentDidUpdate(prevProps, prevState) {
if (this.state !== prevState) {
// update redux state when Information.js state updates
this.props.updateNewEventInfo(this.state);
}
if (prevProps.eventcreation !== this.props.eventcreation) {
// redux prop is updated in component prop (slight delay between redux / prop updates)
}
}
@williamsiuhang
williamsiuhang / shaders-uniform-types
Created February 12, 2019 20:54
Uniform data types for Three js <-> shaders
switch (uniform.type)
{
case 'b':
case 'bool':
case 'boolean':
// single int value
case 'i':
case '1i'
@williamsiuhang
williamsiuhang / mongo-queries.js
Created January 7, 2019 18:40
Basic mongo queries using Node.js / Express
// Connect
function connect() {
var mongoose = require('mongoose');
mongoose
.connect('mongodb://user:pass@ds123456.mlab.com:1234/project', {
useNewUrlParser: true
})
.then(() => {
console.log('MongoDB Connected');
// Fetches SQL table through ajax POST
// console.logs rows as JSON
// =============================== PHP (functions.php)
<?php
add_action( 'wp_ajax_clients', 'sql_get_clients' );
add_action( 'wp_ajax_nopriv_clients', 'sql_get_clients' ); // postman (if user not logged in)
function sql_get_clients() {