Skip to content

Instantly share code, notes, and snippets.

View elado's full-sized avatar
👨‍💻

Elad Ossadon elado

👨‍💻
View GitHub Profile
@elado
elado / node-proxy-https-to-http.js
Created May 10, 2017 22:18
Node Proxy from HTTPS to HTTP + CORS
// 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 February 28, 2017 17:59
CaseChange (object deep camelizer/underscorer)
import _ from 'lodash'
const CaseChange = {
camelizeKey: _.memoize(_.camelCase),
underscoreKey: _.memoize(_.snakeCase),
convertToCamelcase(object) {
return deepMapKeys(object, CaseChange.camelizeKey)
},
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 #!'
@elado
elado / mobxStoresToProps.js
Created October 18, 2016 19:50
mobxStoresToProps
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 October 6, 2016 18:25
Webpack + Asset File Name + Server Rendering

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 September 14, 2016 04:34
MobX/Redux DevTools in root without an extra div

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 February 29, 2020 15:27
Advanced BEM SASS Mixins
@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 March 24, 2019 17:44
Redux Indexed List Reducer Generator
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 November 8, 2018 09:19
STOP ALL GIFS!!!!!! (bookmarklet)
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 December 10, 2015 21:54
Sequel Rake Tasks
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