Skip to content

Instantly share code, notes, and snippets.

View gauthierm's full-sized avatar

Michael Gauthier gauthierm

View GitHub Profile
function getDigitAt(position, value) {
return Math.floor((value % 10 ** position) / 10 ** (position - 1));
}
function getLength(value) {
return Math.floor(Math.log10(value)) + 1;
}
function isPalindrome(value) {
const digits = getLength(value);
async function getAllMyData() {
const rootResponse = await fetch('https://www.myapi.com/foo', { ... });
const rootData = await rootResponse.json();
// this gets all the ids we need for the nested requests from the data
// in the first request
const ids = rootData.bars.map(bar => bar.id);
// fetch all the details of all the bar objects. This makes multiple
import ElasticSwiftCore
import Foundation
import Network
import Logging
import NIOHTTP1
/**
Class maintaining URLSession for a Host
*/
import { StyleSheet } from 'react-native';
import { colors } from '../styles/colors';
import { font } from '../styles/font.styles';
export const styles = StyleSheet.create({
background: {
paddingTop: 8,
paddingRight: 16,
paddingBottom: 8,
paddingLeft: 16,
@gauthierm
gauthierm / settings.json
Last active May 6, 2020 20:26
VS Code settings
{
"files.associations": {
"*.ejs": "html",
"*.jsx": "javascriptreact"
},
"scss.validate": false,
"prettier.requireConfig": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
@gauthierm
gauthierm / MyComponent.js
Last active February 7, 2018 16:41
React component + Jest/Enzyme test
import React from 'react';
import MyButton from './MyButton';
export default function MyComponent(props) {
return (<div>Hello, world! <MyButton>Click Here</MyButton></div>);
}
<?php
$functions = [
'mail',
'strlen',
'strpos',
'strrpos',
'substr',
'strtolower',
'strtoupper',
const fs = require('fs');
// read
fs.readFile('composer.json', 'utf8', (err, contents) => {
if (err) {
console.log('File could not be read');
} else {
try {
// parse
const json = JSON.parse(contents);
@gauthierm
gauthierm / .vimrc
Created March 8, 2017 19:08
.vimrc 2017
" use vim extensions
set nocompatible
" syntax highlighting
syntax on
" user-friendly backspace
set backspace=indent,eol,start
" show command on last line of screen
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
createdAt: DS.attr('date'),
updatedAt: DS.attr('date'),
firstName: DS.attr('string'),
lastName: DS.attr('string'),
suffix: DS.attr('string'),
company: DS.attr('string'),