Skip to content

Instantly share code, notes, and snippets.

Sebastien Hiticas sbtnh

View GitHub Profile
@sbtnh
sbtnh / MyGenericComponent.tsx
Created Jan 22, 2019
React generic component with TypeScript
View MyGenericComponent.tsx
/** Generic component */
type MyComponentProps<T> = { data: T[] }
class MyComponent<T> extends React.Component<MyComponentProps<T>, any> { }
/** Usage */
<MyComponent<number> data={[12, 15, 18]} />
<MyComponent<string> data={["one", "two", "three"]} />
@sbtnh
sbtnh / xmlToJson.js
Created Jul 4, 2018 — forked from demircancelebi/xmlToJson.js
Function to convert XML to JSON
View xmlToJson.js
// Changes XML to JSON
// Modified version from here: http://davidwalsh.name/convert-xml-json
xmlToJson(xml) {
// Create the return object
let obj = {};
if (xml.nodeType === 1) { // element
// do attributes
if (xml.attributes.length > 0) {
obj['@attributes'] = {};
@sbtnh
sbtnh / update-url-query-string-history.js
Last active Jan 9, 2017 — forked from excalq/gist:2961415
Javacript: Set or Update a URL/QueryString Parameter, and update URL using HTML history.replaceState()
View update-url-query-string-history.js
// Explicitly save/update a url parameter using HTML5's replaceState().
function updateQueryStringParam(key, value) {
const baseUrl = [location.protocol, '//', location.host, location.pathname].join('');
const urlQueryString = document.location.search;
let newParam = key + '=' + value;
let params = '?' + newParam;
// If the "search" string exists, then build params from it
if (urlQueryString) {
const keyRegex = new RegExp('([\?&])' + key + '[^&]*');
You can’t perform that action at this time.