Skip to content

Instantly share code, notes, and snippets.

javascript:(function()%7Bdocument.querySelectorAll('.Post%20h2').forEach((element)%20%3D%3E%20%7Bconst%20fullText%20%3D%20element.innerText.split('%20')%3Belement.innerText%20%3D%20fullText%5B0%5D%3Belement.addEventListener('mouseover'%2C%20(event)%20%3D%3E%20%7BsetTimeout(()%20%3D%3E%20%7Bevent.target.dataset.fullText%20%3D%20fullText.join('%20')%3Bevent.target.innerText%20%3D%20event.target.dataset.fullText.split('%20').splice(0%2C%20event.target.innerText.split('%20').length%20%2B%201).join('%20')%3B%7D%2C%201000)%3B%7D)%3B%7D)%7D)()
const React = require('react');
const { connect } = require('react-redux');
const ProductPrice = () => <div/>;
const mapStateToProps = (state) => ({
anyProp: 'foobar',
});
exports.default = connect(mapStateToProps)(ProductPrice);
@leonaves
leonaves / weatherfetch.js
Created October 10, 2017 08:33
Weather Fetch Example
<Connect(Lifecycle(WeatherFetch))> // Holds the logic of interacting with the redux store and mapping the state to its child component's props.
<Lifecycle(WeatherFetch) temperature={temperature} windSpeed={windSpeed} fetch={fetch}> // Holds the logic of calling the fetch function
<WeatherFetch temperature={temperature} windSpeed={windSpeed}> // ?
<WeatherInfo temperature={temperature} windSpeed={windSpeed} />
</WeatherFetch>
</Lifecycle(WeatherFetch)>
</Connect(Lifecycle(WeatherFetch))>
@leonaves
leonaves / canvas.js
Created May 28, 2017 14:31
Colourful bubbles!
const canvas = document.getElementById('header-background');
canvas.width = parseInt(window.getComputedStyle(canvas).width);
canvas.height = parseInt(window.getComputedStyle(canvas).height);
// Set of colors for the dots to be drawn of (HSL notation)
const colors = [
{ h: 360 * 0.95, s: 90, l: 70 },
{ h: 360 * 0.08, s: 90, l: 70 },
{ h: 360 * 0.17, s: 90, l: 70 },
@leonaves
leonaves / functions.php
Last active November 26, 2016 11:52
Sort Order "fix" for hale letting
<?php
add_filter('posts_where' , 'posts_where');
function edit_posts_join_paged($join_paged_statement) {
global $wpdb;
$term_join_table = $wpdb->prefix . "term_relationships";
$term_taxonomy_table = $wpdb->prefix . "term_taxonomy";
$posts_table = $wpdb->prefix . "posts";
@leonaves
leonaves / functionConcat.js
Last active March 18, 2016 03:00
This feels so dirty.
app.get('/', (req, res) =>
res.render('index.html') + req.secondMethod()
);
//Or even filthier:
app.get('/', (req, res) =>
condition == true
? res.render('index.html') + req.secondMethod()
: res.render('other.html') + req.otherMethod()
@leonaves
leonaves / phpstorm_error.js
Created March 9, 2016 12:44
PHP storm error with object property
const mapDispatchToProps = (dispatch) => {
return {
onClickOrder: (orderID) => {
let action = displayOrderInTill(orderID);
if (action !== undefined) dispatch(action);
}
}
};
export default mapDispatchToProps;
@leonaves
leonaves / getInspectedState3.js
Created February 28, 2016 23:58
Version of getInspectedState that supports all Iterables and should be more efficient for Immutable Iterables (Note: needs modified version of objType)
function getInspectedState(state, path, purgeFunctions) {
state = path.length ?
{
[path[path.length - 1]]: path.reduce(
(s, key) => {
if (objType(s) === 'Iterable') {
let i = 0; for (const entry of s) {
if (Array.isArray(entry)) {
if (entry[0] === key) return entry[1];
} else {
@leonaves
leonaves / getInspectedState2.js
Created February 28, 2016 23:57
Version of getInspectedState that supports all Iterables
function getInspectedState(state, path, purgeFunctions) {
state = path.length ?
{
[path[path.length - 1]]: path.reduce(
(s, key) => {
if (objType(s) === 'Iterable') {
let i = 0; for (const entry of s) {
if (Array.isArray(entry)) {
if (entry[0] === key) return entry[1];
} else {