Skip to content

Instantly share code, notes, and snippets.

cahnory

  • Marseille, France
Block or report user

Report or block cahnory

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cahnory
cahnory / WebpackRelayCompilerPlugin.js
Last active Mar 5, 2018
WebpackRelayCompilerPlugin
View WebpackRelayCompilerPlugin.js
const childProcess = require('child_process');
function RelayCompilerPlugin(options) {
this.schema = options.schema;
this.src = options.src;
}
RelayCompilerPlugin.prototype.apply = function(compiler) {
const cmd = `relay-compiler --src ${this.src} --schema ${this.schema}`;
@cahnory
cahnory / UserType.js
Last active Feb 4, 2018
Create relay node field
View UserType.js
import { GraphQLObjectType } from 'graphql';
import { globalIdField } from 'graphql-relay';
import { nodeInterface, defineNodeType } from './node';
import { findById } from '../models/User';
export const UserType = new GraphQLObjectType({
name: 'User',
fields: {
id: globalIdField('User')
@cahnory
cahnory / subscriptionManager.js
Last active Nov 29, 2017
Subscription manager to quickly remove all subs (on componentWillUnmount for eg.)
View subscriptionManager.js
export default createSubscriptionManager = () => {
const subs = []
return {
subscriptions: subs,
interval: attachSubscriptionMethod(subs, interval),
listen: attachSubscriptionMethod(subs, listen),
timeout: attachSubscriptionMethod(subs, timeout),
promise: attachSubscriptionMethod(subs, promise),
@cahnory
cahnory / middleware.js
Created Dec 21, 2015
koa-webpack-middleware
View middleware.js
import connect from 'koa-connect';
import compose from 'koa-compose';
import webpack from 'webpack';
import webpackDev from 'webpack-dev-middleware';
import webpackHot from 'webpack-hot-middleware';
export default function (config = {}) {
let compiler = webpack(config);
return compose([
@cahnory
cahnory / README.md
Created Jan 27, 2017
Idée vite jetée à propos des bundlers
View README.md

Utilisation d'une fonction d'import propre au bundler

Aujourd'hui, webpack nous permet d'inclure un asset comme s'il s'agissait d'un fichier javascript :

import style from './style.css'

Mais les avantages de cette approches ne sont ils pas inférieurs aux inconvéniants ?

View gist:6d47f34f1ce37380f45816426f7517ea
View DataSelect.jsx
import React from 'react'
export function DataSelect({
children,
onData,
onChange,
value,
defaultValue,
...props,
}) {
@cahnory
cahnory / Walker_Nav_Menu_Object.php
Created Feb 18, 2016
Wordpress nav menu object
View Walker_Nav_Menu_Object.php
<?php
class Walker_Nav_Menu_Object extends Walker_Nav_Menu
{
protected $scopes = array();
public function __construct() {
$this->scopes[] = (object)array(
'children' => array(),
'parent' => NULL
@cahnory
cahnory / absolutize.php
Last active Dec 30, 2015
HTML absolutizer
View absolutize.php
<?php
function absolutize($html, $base) {
// href, src, background attributes
$html = preg_replace('#(<[^>]+(href|src|background)=(?:3D)?")(?![a-z]+:)/?([^"]+)"#is', '$1'.$base.'$3"', $html);
// style attributes url(), src()
$html = preg_replace('#(<[^>]+style=(?:3D)?"[^"]*(url|src)\([\s\']*)(?![a-z]+:)/?([^)]+)\)#is', '$1'.$base.'$3)', $html);
// style tag
preg_match_all('#<style[^>]*>([^<]+)#is', $html, $styles);
@cahnory
cahnory / _split.scss
Created Dec 4, 2013
Split rule by selectors
View _split.scss
@mixin split($selectors...) {
@each $selector in $selectors {
#{$selector} {
@content;
}
}
}
You can’t perform that action at this time.