Skip to content

Instantly share code, notes, and snippets.

@jamesmfriedman
jamesmfriedman / gist:cc8ef976888962b3d9a0d252cf7ec2d0
Last active May 19, 2020 17:35
Rename all camelcase files to kebab case, and all ts to tsx because OS is case insensitive love React.
rm -rf temp \
&& mkdir temp \
&& git mv src/* temp \
&& find ./temp -name '*' -type f -exec sh -c "echo '{}' \
| sed 's/\([a-z]\)\([A-Z]\)/\1-\2/g'\
| sed 's/\([A-Z]\{2,\}\)\([A-Z]\)/\1-\2/g' \
| sed 's/\.ts$/\.tsx/g' \
| sed 's/\.\/temp/\.\/src/g' \
| tr '[:upper:]' '[:lower:]' \
| xargs -I newName sh -c 'dirname newName | xargs mkdir -p && git mv --force {} newName'
@jamesmfriedman
jamesmfriedman / proposal.jsx
Last active January 2, 2023 11:11
MDC Foundation Proposal
/**
* Current Adapter Example
* This is a simple adapter, some are extremely complex...
* It is not immediately obvious why some code lives in the adapter and some in the foundation
* The Select alone is over 700 lines of component logic...
**/
MDCCheckboxFoundation({
addClass: (className) => this.root_.classList.add(className),
removeClass: (className) => this.root_.classList.remove(className),
setNativeControlAttr: (attr, value) => this.nativeCb_.setAttribute(attr, value),
@jamesmfriedman
jamesmfriedman / package.json
Last active April 25, 2017 21:23
medium/webpack-inline-styles/package.json
{
"name": "jamesmfriedman",
"version": "1.0.0",
"description": "James Friedman",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --inline --hot --host 0.0.0.0 --port 8080 --env.BUILD_ENV dev --env.NODE_ENV dev",
"dev": "npm start",
"dev:min": "webpack-dev-server --inline --hot --host 0.0.0.0 --port 8080 --env.BUILD_ENV 'dev optimized' --env.NODE_ENV dev",
"clean-dist-folder": "rm -R ./public && mkdir ./public",
@jamesmfriedman
jamesmfriedman / styles.js
Last active April 25, 2017 21:19
medium/webpack-inline-styles/styles
//explicit set of loaders
//use a leading '!' to short circuit any loader rules in the main webpack config.
require('!style-loader!css-loader!sass-loader!./styles/main.scss');
@jamesmfriedman
jamesmfriedman / index.ejs
Created April 25, 2017 20:58
medium/webpack-inline-styles/index
<!DOCTYPE html>
<html>
<head>
<base href="/">
<title>James Friedman: UX / UI Design and Dev Consulting</title>
<!--EXPRESSION-->
<!--This is the magic inline ejs expression-->
<% if (~process.env.BUILD_ENV.search('optimized')) { %>
<style>
@jamesmfriedman
jamesmfriedman / webpack.config.js
Last active April 25, 2017 20:59
medium/webpack-inline-styles/config
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = function(env) {
// merge together build and environment variables
// to be made available in process.env
const processEnv = Object.assign({}, env, require('./env.' + env.NODE_ENV));
// define our entries
const entries = {
var mod = angular.module('CacheView', []);
function addScope(child, parent){
child.$parent = parent;
child.$$prevSibling = parent.$$childTail;
if(child.$$prevSibling) child.$$prevSibling.$$nextSibling = child;
parent.$$childTail = child;
if(!parent.$$childHead) parent.$$childHead = child;
@jamesmfriedman
jamesmfriedman / responsive-image.css
Last active December 22, 2015 02:59
A little utility for creating responsive centered images while still using an img tag. Basic premise, the image size is controlled by the padding value in css, while the real image is set to 0 by 0.
img.responsive-image {
padding: 50%; /*controls the ratio of the image. 37.5% 50% would be a 4 x 3 image*/
width: 0;
height:0;
background-size: cover;
background-position: center center;
}
@jamesmfriedman
jamesmfriedman / rename_table_migration.py
Last active February 8, 2022 18:56
Renaming a Django app that has migrations already sucks. This Is a way I found to do it that preserves your old migration history and keeps your contenttypes in order. The trick is, this migration cannot be in the app you are migrating, so stick it in your "core" app or another app you have installed. Just plug in your own old and new app names.
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from django.db.models import get_app, get_models
class Migration(SchemaMigration):
@jamesmfriedman
jamesmfriedman / fresh.py
Last active February 26, 2018 18:43
A management command that provides a quick way to restart a Django project when you have south installed.
from django.core.management.base import BaseCommand
from django.core import management
from django.conf import settings
from django.db import models
from importlib import import_module
from django.core.management.base import CommandError
from django.contrib.auth.models import User
from django.utils.six.moves import input
class Command(BaseCommand):