Skip to content

Instantly share code, notes, and snippets.

View hgwood's full-sized avatar

Hugo Wood hgwood

View GitHub Profile
@hgwood
hgwood / exercice3.py
Last active November 27, 2019 11:57
Code for the Battle Dev event on 2019-11-26
# This is a revised, cleaned up version of the code for exercise 3
ncables, nreservations = map(int, input().split())
reservations = [tuple(map(int, input().split())) for _ in range(nreservations)]
reservations = [(i, start, end) for (i, (start, end)) in enumerate(reservations)]
assignments = [0 for _ in reservations]
available_cables = set(range(1, ncables + 1))
aborted = False
@hgwood
hgwood / Main.elm
Last active May 4, 2017 22:01 — forked from anonymous/Main.elm
Example Elm program that gets grants from the GitHub API on the click of a button
module Main exposing (..)
import Html exposing (Html, text)
import Html.Events exposing (onClick)
import Json.Decode exposing (..)
import Http
main =
Html.program { init = init, subscriptions = subscriptions, view = view, update = update }
@hgwood
hgwood / brunch-server.js
Last active November 16, 2016 09:04
Here's how to use a Browser Sync server with Brunch. Place this file along side `brunch-config.js`, and start Brunch with the `--server` option.
const browserSync = require('browser-sync');
module.exports = (port, path, callback) => {
const browserSyncServer = browserSync.create();
browserSyncServer.init({
port,
serveStatic: [path],
// Other Browser Sync options go here
}, callback);
return {close: () => browserSyncServer.exit()}
@hgwood
hgwood / zip.js
Created August 23, 2016 13:38
Zipping files using Node.js
const yazl = require('yazl');
function zip(...files) {
const archive = new yazl.ZipFile();
files.forEach(file => archive.addFile(file, file));
archive.end();
return archive.outputStream;
}
@hgwood
hgwood / walk.js
Last active September 6, 2016 14:14
Walking a directory tree synchronously with Node.js 6+
const fs = require('fs');
function walk(root) {
const files = [];
const dirs = [root];
while (dirs.length) {
const dir = dirs.shift();
const dircontent = fs.readdirSync(dir).map(file => path.join(dir, file));
const [newDirs, newFiles] = partition(dircontent, file => fs.statSync(file).isDirectory());
files.push(...newFiles);
@hgwood
hgwood / falgql.js
Last active November 30, 2016 08:40
Example of transforming a GraphQL query into a Falcor query
const assert = require("assert")
const fs = require("fs")
const parser = require("graphql/language/parser")
const _ = require("lodash")
const write = (path, json) => fs.writeFileSync(path, JSON.stringify(json, null, 2))
const inputGraphQl = `
query {
families(name: "Stark") {
@hgwood
hgwood / csv-map.js
Created June 8, 2016 16:12
Transforming CSV data
const fs = require("fs")
// The 3 following modules need to be installed
const csvStream = require("csv-stream")
const csvWriteStream = require("csv-write-stream")
const through2Map = require("through2-map")
fs.createReadStream("in.csv")
.pipe(csvStream.createStream({
// will use the first line as a header containing the keys for the resulting objects
delimiter: ";" // other options: https://www.npmjs.com/package/csv-stream
@hgwood
hgwood / diverge.js
Last active August 29, 2015 14:15
Another example of integrating CommonJS and Angular's DI (replaces diverge.js from https://gist.github.com/hgwood/2f9f11e7eff1f144d675). This one monkey patches $injector and $controllerProvider to apply custom logic when resolving component names.
"use strict";
var _ = require("lodash");
var angular = require("angularjs");
module.exports = function diverge(rootModuleName, ngComponents) {
angular.module(rootModuleName, [])
.config(decorateInjector)
.config(decorateControllerProvider);
@hgwood
hgwood / angular.browserify.js
Created February 10, 2015 13:14
Example of integrating CommonJS with Angular's DI without writing modules
require("angular");
module.exports = angular;
#search-result .ng-enter {
transition: 0.2s linear all;
opacity: 0;
line-height: 0em;
}
#search-result .ng-enter-active {
opacity: 1;
line-height: inherit;
}