Skip to content

Instantly share code, notes, and snippets.


Samuel ROZE sroze

View GitHub Profile
View marker clustering
componentWillReceiveProps(nextProps) {
if (nextProps.lastRequestedUserLocationAt > this.props.lastRequestedUserLocationAt) {
if (nextProps.lastUpdated > this.props.lastUpdated) {
const markers = this.createMarkersForLocations(nextProps);
if (markers && Object.keys(markers)) {
const clusters = {};
MicheleBertoli / demo.js
Created Aug 31, 2016
Erdux - Unpredictable state container for JavaScript apps
View demo.js
class DecrementAction extends Error {}
class IncrementAction extends Error {}
const reducer = (state, error) => {
switch (error.constructor) {
case DecrementAction:
return state - 1
case IncrementAction:
return state + 1
benpickles / action.js
Created Mar 18, 2016
Inject an Authorization header into a redux-api-middleware request with a Redux middleware.
View action.js
import { CALL_API } from 'redux-api-middleware'
export function fetchLocations() {
return {
endpoint: '',
method: 'GET',
// Don't have to manually add the Authorization header to every request.
headers: { 'Content-Type': 'application/json' },
View 001.phpt
001 Annotations
<requires($a >= 0)>
<requires($b >= 0)>
<ensures($ret >= 0)>
function foo($a, $b) {
View git-branch-status
moved to github -->
ismasan / sse.go
Last active Mar 31, 2022
Example SSE server in Golang
View sse.go
// Copyright (c) 2017 Ismael Celis
// 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:
// The above copyright notice and this permission notice shall be included in all
stain / vocabulary-jsonld.json
Last active Mar 3, 2021
Example of how a simple OWL ontology / RDFS vocabulary could be defined with JSON-LD, defining the meaning of properties and classes. The second file shows the RDF triples of the vocabulary by using the JSON-LD sandbox. As a visualization - see…
View vocabulary-jsonld.json
{ "@context": {
"rdf": "",
"rdfs": "",
"owl": "",
"express": "",
"defines": {
"@reverse": "rdfs:isDefinedBy"
"propertyOf": {
"@id": "rdfs:domain",
emiller / git-mv-with-history
Last active May 20, 2022
git utility to move/rename file or folder and retain history with it.
View git-mv-with-history
# git-mv-with-history -- move/rename file or folder, with history.
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
nikic /
Last active May 22, 2022
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

robnyman / Fullscreen API, fullscreenchange.js
Last active Mar 9, 2018
Fullscreen API, fullscreenchange
View Fullscreen API, fullscreenchange.js
document.addEventListener("fullscreenchange", function () {
fullscreenState.innerHTML = (document.fullscreen)? "" : "not ";
}, false);
document.addEventListener("mozfullscreenchange", function () {
fullscreenState.innerHTML = (document.mozFullScreen)? "" : "not ";
}, false);
document.addEventListener("webkitfullscreenchange", function () {
fullscreenState.innerHTML = (document.webkitIsFullScreen)? "" : "not ";