Skip to content

Instantly share code, notes, and snippets.

@sekoyo
sekoyo / conduit.connect.js
Last active December 13, 2020 00:16
Connect to Phabricator with node.js
var Connect = function() {
this.fs = require('fs');
this.crypto = require('crypto');
this.http = require('http');
this.url = require('url');
this.q = require('q');
this.initialize();
};
@sekoyo
sekoyo / conduit.apiquery.js
Created December 20, 2013 14:46
Send a query to phabricator using node.js
var ApiQuery = function() {
this.http = require('http');
this.q = require('q');
this.Connect = require('./conduit.connect');
this.initialize();
};
ApiQuery.prototype = {
initialize: function() {
@sekoyo
sekoyo / gist:94e39847361d7e5b360d
Created July 21, 2014 13:30
Ping Federate SSO
var Q = require('q');
var util = require('util');
var request = require('request');
var _ = require('lodash');
var sso = {};
/**
* Redirect to the SSO login page.
*/
@sekoyo
sekoyo / add.js
Last active September 7, 2016 13:10
function add(...args) {
const sum = args.reduce((prev, curr) => prev + curr, 0);
const ret = add.bind(void 0, sum);
ret.value = ret.valueOf = () => sum;
ret.add = ret;
return ret;
}
console.log(add(1, 2).value() === 3);
console.log(add(1, 2)(3).value() === 6);
@sekoyo
sekoyo / node-sass-functions.js
Last active May 31, 2019 23:38
node-sass external svg to inline
'use strict';
const path = require('path');
const fs = require('fs');
const types = require('node-sass').types;
function svgContentWrapper(svgContent) {
return `url('data:image/svg+xml;charset=UTF-8,${svgContent.replace(/\r?\n|\r/g, '')}')`;
}
/*
Authenticate component using a wrapper
*/
import React, {Component} from 'react';
import { connect } from 'react-redux';
export default function(ComposedComponent) {
class Auth extends Component {
static contextTypes = {
@sekoyo
sekoyo / bem-class.js
Last active March 21, 2019 11:23
BEM Class helper
/*
BEM Class helper:
const c = makeClass('myparentclass');
className={c`myclass myclass--active`}
becomes: className="myparentclass__myclass myparentclass__myclass--active"
*/
export const makeClass = (cls) =>
(subCls) => subCls[0].split(' ').reduce((acc, s) =>
`${acc}${cls}__${s} `, '').trimRight();
@sekoyo
sekoyo / copyToClipboard.js
Last active July 25, 2017 15:49
Copy to clipboard
export const copyToClipboard = (function initClipboardText() {
const id = 'copy-to-clipboard-helper';
const element = document.getElementById(id);
const textarea = element || document.createElement('textarea');
if (!element) {
textarea.id = id;
// Place in top-left corner of screen regardless of scroll position.
textarea.style.position = 'fixed';
textarea.style.top = 0;
@sekoyo
sekoyo / AuthBlockade.js
Last active February 2, 2021 12:22
Example of react-navigate and redux HOC for authenticated routes
/*
Example usage:
StackNavigator({
Login: { screen: Login },
Play: { screen: AuthBlockade(Play) },
}, {
initialRouteName: 'Play',
});
*/
@sekoyo
sekoyo / adaptiveComponent.js
Last active February 2, 2019 19:43
Loading different components at runtime depending on media queries in React
/* globals matchMedia */
import React, { PureComponent } from 'react';
function adaptiveComponent(mediaQueries) {
const firstMatchingQuery = Object.keys(mediaQueries).find(mediaQuery =>
matchMedia(mediaQuery).matches);
if (!firstMatchingQuery) {
throw new Error(`No media query matches found in ${mediaQueries}`);
}