Skip to content

Instantly share code, notes, and snippets.

@elado
elado / node-proxy-https-to-http.js
Created May 10, 2017
Node Proxy from HTTPS to HTTP + CORS
View node-proxy-https-to-http.js
// DO NOT USE IN PRODUCTION.. OBVIOUSLY.
const http = require('http')
const httpProxy = require('http-proxy')
const { argv } = require('yargs')
const proxy = httpProxy.createProxyServer()
proxy.on('error', e => console.log('error', e))
@elado
elado / CaseChange.js
Last active Feb 28, 2017
CaseChange (object deep camelizer/underscorer)
View CaseChange.js
import _ from 'lodash'
const CaseChange = {
camelizeKey: _.memoize(_.camelCase),
underscoreKey: _.memoize(_.snakeCase),
convertToCamelcase(object) {
return deepMapKeys(object, CaseChange.camelizeKey)
},
View tagged-string.js
function urlEncodedTaggedString(strings, ...substitutions) {
let result = strings[0]
for (let i = 0; i < substitutions.length; ++i) {
result += encodeURIComponent(substitutions[i])
result += strings[i + 1]
}
return result
}
let name = 'I have ? and #!'
View mobxStoresToProps.js
import React, { Component } from 'react'
import { omit } from 'lodash-bound'
import { observer, inject } from 'mobx-react'
// usage:
//
// @mobxStoresToProps(['entityStore', 'userStore'], (entityStore, userStore, { conversationId }) => {
// const conversation = entityStore.conversation.getById(conversationId)
// const user = conversation.counterParty
@elado
elado / Webpack + Asset File Name + Server Rendering.md
Last active Oct 6, 2016
Webpack + Asset File Name + Server Rendering
View Webpack + Asset File Name + Server Rendering.md

Webpack + Asset File Name + Server Rendering

webpack.config.js

import AssetsPlugin from 'assets-webpack-plugin'

// ...

export default {
@elado
elado / DevTools-without-an-extra-div.md
Created Sep 14, 2016
MobX/Redux DevTools in root without an extra div
View DevTools-without-an-extra-div.md

MobX/Redux's Provider must get only a single child because it only renders what it gets, and React won't handle multiple objects returned from render.

DevTools are usually rendered at the top level component, but in case that top level component renders a router, it needs another element (e.g. div) to wrap everything. This is not always wanted.

  render() {
    return (
      <Provider {/* ... */}>
        <div className="Root">
          <Router {/* ... */}>
@elado
elado / _bem-mixins.scss
Last active Feb 29, 2020
Advanced BEM SASS Mixins
View _bem-mixins.scss
@mixin reset {
&, * {
margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;
box-sizing: border-box; min-height: 0; min-width: 0;
ul { list-style: none; }
button { width: auto; height: auto; border: 0; background-color: transparent; cursor: pointer; outline: none; line-height: 1; }
}
}
$bem-use-namespace: false !default;
@elado
elado / 01_indexedListReducerGenerator.js
Last active Mar 24, 2019
Redux Indexed List Reducer Generator
View 01_indexedListReducerGenerator.js
import shallowequal from 'shallowequal'
import _ from 'lodash'
export const LIST_UPSERT = '@@list/LIST_UPSERT'
export const LIST_DELETE = '@@list/LIST_DELETE'
const ids = (state=[], action) => {
switch (action.type) {
case LIST_UPSERT: {
const hasAt = typeof action.at !== 'undefined'
@elado
elado / stop-gifs.js
Last active Nov 8, 2018
STOP ALL GIFS!!!!!! (bookmarklet)
View stop-gifs.js
javascript:(function(){function createElement(a,b){var c=document.createElement(a);return b(c),c}function f(a){var e,b=a.width,c=a.height,d=createElement("canvas",function(a){a.width=b,a.height=c}),f=0,g=function(){for(d.getContext("2d").drawImage(a,0,0,b,c),f=0;f<a.attributes.length;f++)e=a.attributes[f],'"'!==e.name&&d.setAttribute(e.name,e.value);d.style.position="absolute",a.parentNode.insertBefore(d,a),a.style.opacity=0};a.complete?g():a.addEventListener("load",g,!0)}function all(){return(new Array).slice.apply(document.images).map(f)}all();})()
@elado
elado / sequel.rake
Created Dec 10, 2015
Sequel Rake Tasks
View sequel.rake
require 'sequel'
require 'yaml'
require 'erb'
Sequel.extension :migration
Sequel.extension :pg_array_ops, :pg_json_ops, :pg_hstore_ops
SEQUEL_MIGRATIONS_PATH = './db/migrate'
def database_name