Skip to content

Instantly share code, notes, and snippets.

Avatar

sunpietro sunpietro

View GitHub Profile
@sunpietro
sunpietro / random-date.js
Created Apr 7, 2019 — forked from miguelmota/random-date.js
Random date in JavaScript
View random-date.js
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
console.log(randomDate(new Date(2012, 0, 1), new Date()));
@sunpietro
sunpietro / sortable-paginated-table.jsx
Created Apr 24, 2018
An example of ReactJS table that has sorting, pagination implemented using getDerivedStateFromProps
View sortable-paginated-table.jsx
import React from "react";
import { render } from "react-dom";
import { MemoizedFlow } from "react-memoize";
const StatelessTable = ({ list, page, onPageChange, onSortChange }) => (
<table border={1} cellPadding={5}>
<thead>
<tr>
<th># counter</th>
<th>data from "list"</th>
@sunpietro
sunpietro / remove_git_tag
Created Nov 6, 2017 — forked from dearaujoj/remove_git_tag
git remove tag locally and remote
View remove_git_tag
git tag -d TagName && git push origin :refs/tags/TagName
@sunpietro
sunpietro / countries.json
Created Apr 2, 2017
List of countries with 2-letter and 3-letter country codes
View countries.json
[
{"name":"Afghanistan","let2":" AF","let3":"AFG"},
{"name":"Albania","let2":"AL","let3":"ALB"},
{"name":"Algeria","let2":"DZ","let3":"DZA"},
{"name":"American Samoa","let2":"AS","let3":"ASM"},
{"name":"Andorra","let2":"AD","let3":"AND"},
{"name":"Angola","let2":"AO","let3":"AGO"},
{"name":"Anguilla","let2":"AI","let3":"AIA"},
{"name":"Antigua and Barbuda","let2":"AG","let3":"ATG"},
{"name":"Argentina","let2":"AR","let3":"ARG"},
@sunpietro
sunpietro / service-workers.md
Created Aug 9, 2016 — forked from Rich-Harris/service-workers.md
Stuff I wish I'd known sooner about service workers
View service-workers.md

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

View services.yml
services:
my.block.custom:
class: My\BlockBundle\Block\CustomBlock
tags:
- { name: landing_page_field_type.block_type, alias: custom }
@sunpietro
sunpietro / CustomBlockExtension.php
Last active Jul 21, 2016
CustomBlockExtension.php
View CustomBlockExtension.php
<?php
namespace My\BlockBundle\DependencyInjection;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
@sunpietro
sunpietro / CustomBlock.php
Last active Jul 21, 2016
CustomBlock.php
View CustomBlock.php
<?php
namespace My\BlockBundle\Block;
use EzSystems\LandingPageFieldTypeBundle\Exception\InvalidBlockAttributeException;
use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Definition\BlockDefinition;
use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Definition\BlockAttributeDefinition;
use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Model\AbstractBlockType;
use EzSystems\LandingPageFieldTypeBundle\FieldType\LandingPage\Model\BlockValue;
View custom.html.twig
<h3>My Custom block</h3>
{{ block }}
View blocks.yml
blocks:
custom:
views:
custom:
template: MyBlockBundle::custom.html.twig
name: My Custom Block view
You can’t perform that action at this time.