Skip to content

Instantly share code, notes, and snippets.

View DylanVann's full-sized avatar
🤖

Dylan Vann DylanVann

🤖
View GitHub Profile
import { useEffect, useRef, useState } from "react";
import "./styles.css";
import { Info } from "@mui/icons-material";
import { Box } from "@mui/material";
import { CSSTransition } from "react-transition-group";

const lorem = (
  <p>
@DylanVann
DylanVann / color-mode.js
Last active October 7, 2020 15:43
Color mode switcher in vanilla JS.
const g=()=>{let l=!1;const s="color-mode",h=["light","dark"],C=o=>h.includes(o)?o:"light",n=o=>o?"dark":"light",e=matchMedia("(prefers-color-scheme: dark)"),i=n(e.matches),u="light",d=localStorage.getItem(s);d!==null&&(l=!0);let c=u;d?c=C(d):i&&(c=i);let t;const r=(o,f)=>{document.body.classList.remove(t),document.body.classList.add(o),f&&(localStorage.setItem(s,o),l=!0),t=o,a.forEach(m=>m(o))},a=new Set,M=o=>{l||r(n(o.matches),!1)};return e.addEventListener?e.addEventListener("change",M):e.addListener(M),document.addEventListener("DOMContentLoaded",()=>r(c,!1)),{subscribe:o=>(o(t),a.add(o),()=>a.delete(o)),set:o=>{r(o,!0)},update:o=>{r(o(t),!0)}}},S=g();window.__color_mode__=S;
@DylanVann
DylanVann / MyContainer.js
Last active November 6, 2017 17:31
Redux Container Concise Example
import { connect } from 'react-redux'
import { createStructuredSelector } from 'reselect'
import MyComponent from './MyComponent'
import { getName, getEmail, onEmailChanged, onNameChanged } from './userReducer'
export default connect(
createStructuredSelector({
name: getName,
email: getEmail,
}),
@DylanVann
DylanVann / MyContainer.js
Last active November 6, 2017 17:31
Redux Container Verbose Example
import { connect } from 'react-redux'
import MyComponent from './MyComponent'
function mapStateToProps(state) {
return {
name: state.user.name,
email: state.user.email,
}
}

redux-saga-request

A helper for running async functions and dispatching actions in redux saga.

import { createRequest, request } from 'redux-saga-request'

// Create your request types.
const FETCH_STUFF = createRequest('FETCH_STUFF')
<?php
function wpp_get_posts($args) {
global $wpdb;
$prefix = $wpdb->prefix;
$wpp_prefix = $wpdb->prefix . "popularposts";
$select = "SELECT SQL_CALC_FOUND_ROWS";
$from = " FROM";
@DylanVann
DylanVann / ViewController.swift
Created June 4, 2015 16:38
A UITableViewController that displays a DatePickerCell and a default UITableViewCell.
import UIKit
import DatePickerCell
class ViewController: UITableViewController {
var cells:NSArray = []
override func viewDidLoad() {
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 44
@DylanVann
DylanVann / DVColorLockView.h
Created October 23, 2014 08:23
DVColorLockView - Objective-C
#import <Foundation/Foundation.h>
@interface DVColorLockView : UIView
@property (nonatomic, strong) UIColor *lockedBackgroundColor;
@end
- (void)viewDidLaod {
//Create cells.
_tableViewData = @[
@{
@"title" : @"Section 1",
@"cells" : @[
_eventCell
]},