Skip to content

Instantly share code, notes, and snippets.

View whoisryosuke's full-sized avatar
👾
Going deep with game development

Ryosuke whoisryosuke

👾
Going deep with game development
View GitHub Profile
@whoisryosuke
whoisryosuke / timestamp-hash.js
Created January 19, 2021 00:05
JS - Generate semi-unique hash based off timestamp
const hash = Number(new Date).toString(36)
@whoisryosuke
whoisryosuke / laravel-api-resource-collection.php
Last active July 12, 2023 18:48
Laravel - API Resources - How to change the collection array that gets returned using the transform method
<?php
class PageResourceCollection extends ResourceCollection
{
public function toArray($request)
{
return [
'data' => $this->collection->transform(function($page){
return [
'id' => $page->id,
'title' => $page->title,
@whoisryosuke
whoisryosuke / index.html
Created December 28, 2021 19:31 — forked from vhashimotoo/index.html
Dialog Invoke Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dialog Example</title>
</head>
<body>
<h1>Dialog Example</h1>
<button id="execute-dialog">Click to show dialog</button>
@whoisryosuke
whoisryosuke / telescope-for-staging.md
Created August 9, 2019 17:38
Laravel / Telescope - Enable telescope for a staging or other environment - via: https://github.com/laravel/telescope/issues/76

If you've been following the instructions in the section "Installing Only In Specific Environments" you'll need to ensure that you update your AppServiceProvider accordingly, e.g.

    public function register()
    {
    	if ($this->app->environment('local') || $this->app->environment('staging')) {
    		$this->app->register(TelescopeServiceProvider::class);
    	}
    }
@whoisryosuke
whoisryosuke / js-get-href-of-target.js
Created September 16, 2019 18:37
JS - Get attribute of event target (e.g. get href on click)
event = event || window.event;
var el = event.target || event.srcElement;
if (el instanceof HTMLAnchorElement)
{
console.log(el.getAttribute('href'));
}
@whoisryosuke
whoisryosuke / nextjs-hoc-authorization.js
Created June 26, 2018 22:24
ReactJS - NextJS - A HOC for wrapping NextJS pages in an authentication check. Checks for getInitialProps on the child component and runs it, so you still get SSR from the page. Also includes a user agent for Material UI.
import React, {Component} from 'react'
import Router from 'next/router'
import AuthService from './AuthService'
export default function withAuth(AuthComponent) {
const Auth = new AuthService('http://localhost')
return class Authenticated extends Component {
static async getInitialProps(ctx) {
// Ensures material-ui renders the correct css prefixes server-side
@whoisryosuke
whoisryosuke / transparent-egui-window.rs
Created April 24, 2023 19:48
egui / Bevy - Transparent Window styling
fn ui_example_system(mut contexts: EguiContexts) {
// Set window styles
let ctx = contexts.ctx_mut();
let old = ctx.style().visuals.clone();
ctx.set_visuals(egui::Visuals {
window_fill: Color32::TRANSPARENT,
panel_fill: Color32::TRANSPARENT,
window_stroke: egui::Stroke {
color: Color32::TRANSPARENT,
width: 0.0,
@whoisryosuke
whoisryosuke / package.json
Created March 11, 2021 16:30
Babel/Typescript/NPM - How to build CJS, ESM, and Types using Babel and Typescript
"scripts": {
"build": "concurrently yarn:build:*",
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps",
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps",
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
"dev": "tsc --watch"
},
@whoisryosuke
whoisryosuke / vs-code-settings.json
Last active April 12, 2023 18:34
VSCode - My overall settings
{
"workbench.colorTheme": "Night Owl",
"editor.fontFamily": "FiraCode Nerd Font",
"editor.fontSize": 14,
"editor.lineHeight": 21,
"workbench.iconTheme": "material-icon-theme",
"editor.multiCursorModifier": "ctrlCmd",
"editor.snippetSuggestions": "top",
"editor.formatOnPaste": true,
// Format a file on save. A formatter must be available, the file must not be auto-saved, and editor must not be shutting down.
@whoisryosuke
whoisryosuke / Header.tsx
Created November 3, 2020 07:19
Styled Components / Typescript - Header component with variants using a switch statement
import React, { memo } from 'react'
import styled from 'styled-components'
import { t, ti } from '../../utils/getTheme'
interface Props {
variant: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
children: JSX.Element
as?: JSX.Element
}