Skip to content

Instantly share code, notes, and snippets.

View pinyin's full-sized avatar
🎯
Focusing

Bao Bo pinyin

🎯
Focusing
View GitHub Profile
class Identifiable<T> {
Id<T> id;
}
class Id<T> {}
class Person extends Identifiable<Person> {}
class Animal extends Identifiable<Animal> {}
@aderaaij
aderaaij / getComputedTranslateXY.ts
Last active February 12, 2023 15:19
Get the computed Translate X and Y values of a given DOM element. Based on https://stackoverflow.com/questions/21912684/how-to-get-value-of-translatex-and-translatey
function getTranslate(item: HTMLElement): number | number[] | undefined {
const transArr = [];
if (!window.getComputedStyle) {
return;
}
const style = window.getComputedStyle(item);
const transform = style.transform || style.webkitTransform;
let mat = transform.match(/^matrix3d\((.+)\)$/);
if (mat) {
return parseFloat(mat[1].split(', ')[13]);
@zxbodya
zxbodya / render-react-with-rxjs.md
Last active November 1, 2021 08:49
React with RxJS, reactive way :)

Observable React elements with RxJS

Note: if you want to skip history behind this, and just looking for final result see: rx-react-container

When I just started using RxJS with React, I was subscribing to observables in componentDidMount and disposing subscriptions at componentWillUnmount.

But, soon I realised that it is not fun to do all that subscriptions(that are just updating property in component state) manually, and written mixin for this...

Later I have rewritten it as "high order component" and added possibility to pass also obsarvers that will receive events from component.

@tkafka
tkafka / LICENSE.txt
Last active May 17, 2024 02:08
Drop-in replacement for ReactCSSTransitionGroup that uses velocity.js instead of CSS transforms. Add your own transitions to `transitions` hash.
The MIT License (MIT)
Copyright (c) 2014 Tomas Kafka
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@roman01la
roman01la / web-worker-cors.js
Created September 9, 2014 17:26
Cross-origin solution for loading WebWorker
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function() {
if (xhr.status === 200) {
var workerSrcBlob, workerBlobURL;
workerSrcBlob = new Blob([xhr.responseText], { type: 'text/javascript' });
workerBlobURL = window.URL.createObjectURL(workerSrcBlob);
var worker = new Worker(workerBlobURL);
@staltz
staltz / introrx.md
Last active July 8, 2024 15:46
The introduction to Reactive Programming you've been missing
@johnthethird
johnthethird / ReactRenderer.rb
Created February 2, 2014 19:01
React Server-Side Rendering for Rails
require 'connection_pool'
class ReactRenderer
mattr_accessor :pool
def self.setup!
size = ::Rails.configuration.react.max_renderers || 10
timeout = ::Rails.configuration.react.renderer_timeout || 20 #seconds
@@pool ||= ConnectionPool.new(:size => size, :timeout => timeout) { ReactRenderer.new }
@bzerangue
bzerangue / recursive-convert-js-to-coffeescript.sh
Created December 11, 2012 00:23
RECURSIVELY Bash convert Javascript to Coffeescript; and also Coffeescript to Javascript
find . -name "*.js" | while read i; do js2coffee "$i" > "${i%.*}.coffee"; done