Skip to content

Instantly share code, notes, and snippets.

Nik Butenko nkbt

Block or report user

Report or block nkbt

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
@nkbt
nkbt / example.jsx
Created May 2, 2019 — forked from bvaughn/example.jsx
Advanced example for manually managing subscriptions in an async-safe way using hooks
View example.jsx
import React, { useMemo } from "react";
import useSubscription from "./useSubscription";
// In this example, "source" is an event dispatcher (e.g. an HTMLInputElement)
// but it could be anything that emits an event and has a readable current value.
function Example({ source }) {
// In order to avoid removing and re-adding subscriptions each time this hook is called,
// the parameters passed to this hook should be memoized.
const subscription = useMemo(
() => ({
@nkbt
nkbt / osx-home-end.sh
Created Feb 6, 2018
Proper home/end bindings for OSX
View osx-home-end.sh
mkdir -p $HOME/Library/KeyBindings
echo '{
/* Remap Home / End keys to be correct */
"\UF729" = "moveToBeginningOfLine:"; /* Home */
"\UF72B" = "moveToEndOfLine:"; /* End */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* Shift + End */
"^\UF729" = "moveToBeginningOfDocument:"; /* Ctrl + Home */
"^\UF72B" = "moveToEndOfDocument:"; /* Ctrl + End */
"$^\UF729" = "moveToBeginningOfDocumentAndModifySelection:"; /* Shift + Ctrl + Home */
@nkbt
nkbt / glob.js
Created Feb 2, 2018
My own slow and unoptimised glob
View glob.js
const process = require('process');
const fs = require('fs');
const util = require('util');
const readdir = util.promisify(fs.readdir);
const realpath = util.promisify(fs.realpath);
const stat = util.promisify(fs.stat);
const ls = async (cwd, paths = []) => {
for (let p of (await readdir(cwd))) {
const rp = await realpath(`${cwd}/${p}`);
@nkbt
nkbt / perf.js
Created Feb 2, 2018
Namespaced perf measurer
View perf.js
const perfCache = {start: {}, end: {}};
const perf = key => {
if (key in perfCache.end) {
return perfCache.end[key];
}
if (key in perfCache.start) {
const [s, ns] = process.hrtime(perfCache.start[key]);
Object.assign(perfCache.end, {[key]: (s + ns / 1e9)});
return perfCache.end[key];
}
@nkbt
nkbt / node-require-url.js
Last active Apr 23, 2018
Async require library from URL for Node
View node-require-url.js
const https = require('https');
const vm = require('vm');
const requireCache = {};
const requireUrl = url => new Promise((resolve, reject) => url in requireCache ?
resolve(requireCache[url]) :
https.get(url, res => {
const result = [];
res.on('data', chunk => result.push(chunk.toString('utf-8')));
View facebook.css
#leftCol {
position: fixed;
}
#rightCol{
display:none;
}
#pagelet_sidebar {
display:none;
View pr-remote.gitconfig
[remote "pr"]
url = git@github.com:nkbt/react-collapse.git
fetch = +refs/pull/*/head:refs/remotes/pr/*
@nkbt
nkbt / Filters.jsx
Last active Apr 8, 2018
ImmutableJS + Redux
View Filters.jsx
import React from 'react';
import {List} from 'immutable';
import {shouldComponentUpdate} from 'react-addons-pure-render-mixin';
import {connect} from 'react-redux';
import getFiltersData from './filtersData';
import {filtersDataReady} from './reducer';
const Filters = React.createClass({
propTypes: {
getFiltersData: React.PropTypes.func.isRequired,
View i18n in react problem.md

Hi all, we have a problem doing i18n with React. This is about template strings.

What we need:

<p>
  By clicking SignUp, you accept our <a href="/terms">Terms of Service</a>
</p>

How I would do it (not in React):

View ruby-wtf.md
module Test
  def get
    y x
  end

  def x
    'x'
  end
You can’t perform that action at this time.