Skip to content

Instantly share code, notes, and snippets.


  • 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
View index.js
export const closestToZero = input => {
if (!(Array.isArray(input) && input.length)) {
return 0;
return input.reduce((prev, value) => {
const ratio = Math.abs(prev / value);
if (ratio > 1 || (ratio === 1 && value > 0)) {
return value;
cahnory / WebpackRelayCompilerPlugin.js
Last active Mar 5, 2018
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 / 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 / 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 / middleware.js
Created Dec 21, 2015
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 /
Created Jan 27, 2017
Idée vite jetée à propos des bundlers

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({
}) {
cahnory / Walker_Nav_Menu_Object.php
Created Feb 18, 2016
Wordpress nav menu object
View Walker_Nav_Menu_Object.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 / absolutize.php
Last active Dec 30, 2015
HTML absolutizer
View absolutize.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);
You can’t perform that action at this time.