Skip to content

Instantly share code, notes, and snippets.

View sroze's full-sized avatar

Samuel ROZE sroze

View GitHub Profile
componentWillReceiveProps(nextProps) {
if (nextProps.lastRequestedUserLocationAt > this.props.lastRequestedUserLocationAt) {
this.centerMapToUser(nextProps.currentLocation);
}
if (nextProps.lastUpdated > this.props.lastUpdated) {
const markers = this.createMarkersForLocations(nextProps);
if (markers && Object.keys(markers)) {
const clusters = {};
@MicheleBertoli
MicheleBertoli / demo.js
Created August 31, 2016 10:49
Erdux - Unpredictable state container for JavaScript apps
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
benpickles / action.js
Created March 18, 2016 16:19
Inject an Authorization header into a redux-api-middleware request with a Redux middleware.
import { CALL_API } from 'redux-api-middleware'
export function fetchLocations() {
return {
[CALL_API]: {
endpoint: 'http://api.somesite.com/api/locations',
method: 'GET',
// Don't have to manually add the Authorization header to every request.
headers: { 'Content-Type': 'application/json' },
types: ['REQUEST', 'SUCCESS', 'FAILURE']
--TEST--
001 Annotations
--FILE--
<?php
<check>
<optimization_level(2)>
<requires($a >= 0)>
<requires($b >= 0)>
<ensures($ret >= 0)>
function foo($a, $b) {
moved to github --> https://github.com/bill-auger/git-branch-status/
@ismasan
ismasan / sse.go
Last active March 19, 2024 18:13
Example SSE server in Golang
// 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
stain / vocabulary-jsonld.json
Last active October 10, 2022 10:54
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 http://www.essepuntato.it/lode/owlapi/https://gist.github.com/stain/7690362/raw/114f836a64291a3f894c44…
{ "@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"owl": "http://www.w3.org/2002/07/owl#",
"express": "http://example.com/express#",
"defines": {
"@reverse": "rdfs:isDefinedBy"
},
"propertyOf": {
"@id": "rdfs:domain",
@emiller
emiller / git-mv-with-history
Last active April 17, 2024 21:06
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# 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
nikic / objects_arrays.md
Last active April 12, 2024 17:05
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
robnyman / Fullscreen API, fullscreenchange.js
Last active March 9, 2018 19:51
Fullscreen API, fullscreenchange
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 ";