Skip to content

Instantly share code, notes, and snippets.

Hugo HugoDF

Block or report user

Report or block HugoDF

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@HugoDF
HugoDF / build-lunrjs-index.js
Last active Aug 11, 2019
Integrate lunrjs with a Hugo (gohugo.io) site.
View build-lunrjs-index.js
const fs = require('fs').promises;
const {promisify} = require('util');
const frontMatterParser = require('parser-front-matter');
const parse = promisify(frontMatterParser.parse.bind(frontMatterParser));
async function loadPostsWithFrontMatter(postsDirectoryPath) {
const postNames = await fs.readdir(postsDirectoryPath);
const posts = await Promise.all(
postNames.map(async fileName => {
@HugoDF
HugoDF / newsletter-bookmarks.js
Created Apr 28, 2019
Netlify Lambda (has to be build using netlify-lambda library) to fetch pocket entries tagged as "newsletter"
View newsletter-bookmarks.js
import axios from 'axios'
const {
POCKET_CONSUMER_KEY,
POCKET_ACCESS_TOKEN
} = process.env
async function fetchBookmarks() {
const res = await axios.post('https://getpocket.com/v3/get', {
consumer_key: POCKET_CONSUMER_KEY,
@HugoDF
HugoDF / settings.json
Created Feb 3, 2019
Disable autocomplete and IntelliSense in Visual Studio Code, put this in your `.vscode` folder, researched as part of https://codewithhugo.com/async-js
View settings.json
{
"editor.quickSuggestions": {
"other": false,
"comments": false,
"strings": false
},
"editor.parameterHints.enabled": false
}
@HugoDF
HugoDF / package.json
Created Jul 24, 2018
Express server rendered app with Pug and SCSS
View package.json
{
"name": "express-pug-scss-starter",
"version": "1.0.0",
"description": "Express server rendered app with Pug and SCSS",
"main": "server.js",
"config": {
"app": "server.js",
"scss": "./src/scss",
"css": "./dist/css",
"img_src": "./src/img/",
@HugoDF
HugoDF / map-snake-to-camel.js
Created Jun 8, 2018
Map snake_case to camelCase recursively
View map-snake-to-camel.js
const delimiterRegEx = /(_\w)/g;
export function convertSnakeToCamelCase (str) {
return str.replace(delimiterRegEx, ([delimiter, firstChar]) =>
firstChar.toUpperCase()
);
}
export const convertKeysToCamelCase = obj =>
Object.entries(obj).reduce((prev, [key, value]) => {
if (value && typeof value === 'object') {
View generate_html_swagger.sh
swagger-codegen generate -i <path to your swagger file> -l html2 -o <path to output location>
@HugoDF
HugoDF / range.js
Last active Jun 26, 2017
Takes a start and end value for an integer range and returns an array containing the range.
View range.js
const range = (first, last) => {
const firstValue = last ? first : 1;
const length = last ? last - first + 1 : first;
return Array.from({ length })
.map((_, i) => i + firstValue);
}
@HugoDF
HugoDF / test.js
Last active Apr 18, 2017
Stub getter with sinon.
View test.js
const mockNode = {
get firstChild() {
return undefined;
}
};
const stubFirstChildGetter = sinon.stub().returns(false).onFirstCall().returns(true);
sinon.stub(mockNode, 'firstChild')
.get(stubFirstChildGetter);
@HugoDF
HugoDF / example.jsx
Last active Jan 12, 2017
Example of partial application in JavaScript applied to React Component event handlers
View example.jsx
class MyComponent extends React.Component {
partialHandleLinkClick(type, activeType){
return function(e) {
const hasKeyboardModifier = e.ctrlKey || e.shiftKey || e.altKey || e.metaKey;
updateType(type, activeType, hasKeyboardModifier);
};
}
render() {
const types = [ 'Foo', 'Bar', 'Baz' ];
return (
@HugoDF
HugoDF / package.json
Created Oct 21, 2016
Library development with ES6, Babel, Mocha and npm scripts
View package.json
{
"name": "library-js",
"version": "1.0.0",
"description": "Starter for library development with ES6, Babel, Mocha and npm scripts",
"main": "./dist/index.js",
"scripts": {
"start": "npm run dev",
"dev": "npm test -- -w",
"init": "mkdir dist",
"clean": "rm -rf dist",
You can’t perform that action at this time.