Skip to content

Instantly share code, notes, and snippets.

View idmontie's full-sized avatar

Ivan Montiel idmontie

View GitHub Profile
class Tween extends Component {
static defaultProps = {
duration: 1000,
}
constructor(props) {
super(props);
this.state = {
timeStart: +new Date(),
class MousePosition extends Component {
constructor(props) {
super(props);
this.onMouseMove = this._onMouseMove.bind(this);
this.state = { x: 0, y: 0 };
}
componentDidMount() {
document.addEventListener('mousemove', this.onMouseMove);
class App extends Component {
render() {
return (
<MousePosition>
{({ x, y }) => (
<Tween func={linear} defaultStart={centerX} end={x}>
{({ current: cx }) => (
<Tween func={linear} defaultStart={centerY} end={y}>
{({ current: cy }) => (
<Rectangle x={cx} y={cy} />
const Rectangle = ({ x, y }) => (
<div style={{ position: 'fixed', top: `${y}px`, left: `${x}px`, height: '10px', width: '10px', backgroundColor: 'black' }} />
);
class App extends Component {
render() {
return (
<SimpleTween start={0} end={600}>
{({ current }) => (
<Rectangle x={current} y={600} />
)}
</SimpleTween>
);
}
class SimpleTween extends Component {
static defaultProps = { duration: 1000 }
constructor(props) {
super(props);
this.state = {
timeStart: +new Date(),
current: props.start,
};
function linear(diff, start, change, duration) {
return change * (diff /= duration) + start;
}
@idmontie
idmontie / App.js
Last active April 6, 2018 22:30
Mouse Move Example
const centerX = Math.floor(window.innerWidth / 2);
const centerY = Math.floor(window.innerHeight / 2);
class App extends Component {
render() {
return (
<MousePosition>
{({ x, y }) => (
<Tween func={easeOutQuad} defaultStart={centerX} end={x}>
{({ current: cx }) => (
@idmontie
idmontie / beep
Created March 29, 2018 08:58
Bash script to let you know when a command finishes
#!/bin/bash
# Add this file to your bash path
# Make sure to chmod 755 it
# Example useage:
# MY_COMMAND; beep
if [ "$?" = "0" ]; then
afplay /System/Library/Sounds/Submarine.aiff -v 8
else
@idmontie
idmontie / framebust.html
Last active March 17, 2018 20:34
Make sure you aren't iframed!
<!-- Crazy, but consistent method: -->
<style>
body { display: none; }
</style>
<script>
if (self === top) {
documents.getElementsByTagName("body")[0].style.display = 'block';
} else {
top.location = self.location;