Skip to content

Instantly share code, notes, and snippets.


sunpietro sunpietro

View GitHub Profile
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 / 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}>
<th># counter</th>
<th>data from "list"</th>
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 / 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":"American Samoa","let2":"AS","let3":"ASM"},
{"name":"Antigua and Barbuda","let2":"AG","let3":"ATG"},
sunpietro /
Created Aug 9, 2016 — forked from Rich-Harris/
Stuff I wish I'd known sooner about service workers

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

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
class: My\BlockBundle\Block\CustomBlock
- { name: landing_page_field_type.block_type, alias: custom }
sunpietro / CustomBlockExtension.php
Last active Jul 21, 2016
View CustomBlockExtension.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 / CustomBlock.php
Last active Jul 21, 2016
View CustomBlock.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
template: MyBlockBundle::custom.html.twig
name: My Custom Block view