Skip to content

Instantly share code, notes, and snippets.

@corysimmons
corysimmons / wp_users_plus_wp_usermeta.sql
Created February 11, 2019 20:27
Combine wp_users and wp_usermeta into a single table with columns (for wp_users) and a big JSON object (for all the wp_usermeta junk).
SELECT
u.id,
u.user_login,
concat('{ ' , group_concat(concat(m.meta_key, ': ''', m.meta_value, '''')) , ' }' ) AS meta
FROM
wp_users AS u
JOIN
wp_usermeta AS m
WHERE
u.id = m.user_id
@corysimmons
corysimmons / selenium_chromedriver_nightwatch.md
Last active July 17, 2018 18:47
How to get Selenium + chromedriver + Nightwatch working.

https://npm.im/selenium-standalone doesn't work with recent versions of JDK and will cause Nightwatch to explode.

selenium-standalone

export JAVA_HOME=/usr/libexec/java_home -v 1.8
import { Dimensions, PixelRatio } from 'react-native'
const { width, height } = Dimensions.get(`window`)
export const vw = size => size * width / PixelRatio.getPixelSizeForLayoutSize(100) / PixelRatio.get()
export const vh = size => size * height / PixelRatio.getPixelSizeForLayoutSize(100) / PixelRatio.get()
export const vmin = Math.min(vw, vh)
export const vmax = Math.max(vw, vh)
@corysimmons
corysimmons / DimensionWatcher.js
Created February 16, 2018 11:52
Wrap things in this. Get map dimension state as props on children. ⚠️Doesn't re-render anything because God is a lie.
import React, { Fragment } from 'react'
import { Dimensions } from 'react-native'
import { connect } from 'react-redux'
class DimensionWatcher extends React.Component {
handleDimensionsChange = dimensions => this.props.dispatch({
type: `DIMENSIONS_CHANGED`,
payload: dimensions,
})
@corysimmons
corysimmons / Dimensions.js
Created February 16, 2018 10:41
WIP React component to get dimensions of screen.
import React, { Fragment } from 'react'
import { Dimensions } from 'react-native'
export default class ScreenMediaQuery extends React.Component {
state = {
dimensions: {
width: Dimensions.get(`window`).width,
height: Dimensions.get(`window`).height,
mode: Dimensions.get(`window`).width > Dimensions.get(`window`).height ? `landscape` : `portrait`,
},
@corysimmons
corysimmons / flatMap.js
Created November 15, 2017 22:10
Convert an object to an array with the object keys chained with dots. So `{ a: 1, b: { c: 2 } }` comes back as `['a', 'b.c']`
const isNumeric = value => (value == Number(value)) ? 'number' : 'string' // eslint-disable-line
let keys = []
let prependable = ''
const flatMap = obj => {
Object
.keys(obj)
.forEach(key => {
if (typeof obj[key] !== 'object' && isNumeric(key) !== 'number') {
keys.push(`${prependable}${key}`)
@corysimmons
corysimmons / crud.php
Created August 27, 2017 17:13
Simple PHP CRUD CLI. Requires db with table `misc` and column `some_string`.
<?php
// Initialize database connection
$db = new PDO('mysql:host=localhost;dbname=phpcrud;charset=utf8mb4', 'root', '');
switch ($argv[1]) {
// CREATE
case 'create':
$stmt = $db->prepare("INSERT misc SET some_string=?");
$stmt->execute([$argv[2]]);
app.use(async (ctx, next) => {
try {
await next()
ctx.body = normalizeInterface(ctx)
} catch (err) {
ctx.body = normalizeInterface(ctx, err)
}
})
app.use(async (ctx) => {
@corysimmons
corysimmons / index.html
Created August 17, 2017 13:23
nodemon + BrowserSync
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
<pre></pre>
const postcss = require('postcss')
const parser = require('postcss-values-parser')
module.exports = postcss.plugin('postcss-ratios', function (opts) {
opts = opts || {}
return (css, result) => {
css.walkRules(rule => {
rule.walkDecls(decl => {
decl.value = parser(decl.value, { loose: true })