Skip to content

Instantly share code, notes, and snippets.

View ivan-kleshnin's full-sized avatar
🏠
Working from home

Ivan Kleshnin ivan-kleshnin

🏠
Working from home
View GitHub Profile
@ohanhi
ohanhi / frp.md
Last active December 23, 2022 13:06
Learning FP the hard way: Experiences on the Elm language

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Editorial note

@sebmarkbage
sebmarkbage / Enhance.js
Last active January 31, 2024 18:33
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@ivan-kleshnin
ivan-kleshnin / bash.npm_package_is_installed.sh
Created January 31, 2015 12:25
Check npm package is installed
function npm_package_is_installed {
if [ $(npm list --depth 0 --parseable true "${2}" | grep "${1}$") ]; then
echo "1"
else
echo "0"
fi
}
# npm_package_is_installed gulp
# npm_package_is_installed gulp -g

2015-01-29 Unofficial Relay FAQ

Compilation of questions and answers about Relay from React.js Conf.

Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.

What is Relay?

Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).

@ivan-kleshnin
ivan-kleshnin / lwip.utils.js
Last active August 29, 2015 14:12
Resize with lwip
// resolution is [width, height] structure
// Evaluate resolution by width (height doesn't matter, just keep it proportional)
function evalResolutionByWidth(requiredWidth, actualResolution) {
var actualWidth = actualResolution[0];
var actualHeight = actualResolution[1];
if (actualWidth > requiredWidth) {
var scale = actualWidth / requiredWidth;
return [requiredWidth, Math.round(actualHeight / scale)];
} else {
@ivan-kleshnin
ivan-kleshnin / .goaccessrc
Last active August 29, 2015 14:10
How to reveal hackers and spammers in standard nginx logs (OS X instruction)
# put this file in home folder
date_format %d/%b/%Y
log_format %h %^[%d:%^] "%r" %s %b "%R" "%u"
@ivan-kleshnin
ivan-kleshnin / gist:6b17b0f6ac863cb17217
Created October 9, 2014 09:40
MongoDB: order positions by timedelta between CLOSE_DATE and NOW
from pymongo import MongoClient
from bson import SON
from time import mktime
from datetime import datetime, timedelta
from time import mktime
from pprint import pprint
from random import randrange, randint, choice
def seed_position_times(db):
@ivan-kleshnin
ivan-kleshnin / gist:601503b9062ba45863d5
Last active December 30, 2022 05:57
Brainstorming middleware ordering... Wider application though.
;; 0. Given that `app` is a RING handler
;; 1. We have 6 functions: 3 to modify requests, 3 to modify responses
;; 1.1. Request modifiers
(defn modify-request-first [handler]
(fn [request]
(println "modify-request-first") ; "println" is a placeholder for real code
(handler request)))
@staltz
staltz / introrx.md
Last active April 25, 2024 04:18
The introduction to Reactive Programming you've been missing
class PPrintMixin:
def __str__(self):
return '<{}: id={!r}>'.format(type(self).__name__, self.id)
def __repr__(self):
attrs = []
for name in self._fields.keys():
value = getattr(self, name)
if isinstance(value, (Document, EmbeddedDocument)):
attrs.append('\n {} = {!s},'.format(name, value))