Skip to content

Instantly share code, notes, and snippets.

View seb-thomas's full-sized avatar
💭
😷

Sebastian Thomas seb-thomas

💭
😷
View GitHub Profile
@seb-thomas
seb-thomas / uniqueArrayObjectProperty.js
Created March 7, 2019 12:34
Various array methods for unique by object value
const myArray = [{name: "terry", id: 1}, {name: "terry", id: 2}, {name: "john", id: 3}]
// Reduce + Filter
myArray.reduce( ( acc, cur ) => [
...acc.filter( ( obj ) => obj.name !== cur.name ), cur
], [] );
// Acc builds up, but starts off small so more manageable.
// Reduce + Find
<label class="label" for="postcodeInput">Postcode</label>
<div class="field has-addons">
<div class="control is-expanded">
<input id="postcodeInput" class="input" type="text" placeholder="E8 1BQ" value="sw15 2pw">
</div>
<div class="control">
<a id="submit" class="button is-primary">Go</a>
</div>
</div>
(function () {
var submit = document.getElementById('submit')
var input = document.getElementById('postcodeInput')
var results = document.getElementById('results')
var stores = [
{
name: 'The Good Wine Shop',
lat: 51.4934165703256,
lng: -0.249506824970951
},
@seb-thomas
seb-thomas / travis.yaml
Last active May 4, 2018 11:43
Travis script with deploy
language: node_js
node_js:
- stable
addons:
ssh_known_hosts: xxx.webfaction.com
env:
global:
secure: xxx-DEPLOY_USER-as-encrypted-string-xxx
after_success:
- npm run coverage
@seb-thomas
seb-thomas / arg-to-array.js
Created February 19, 2017 12:04
Pass an argument to Array.map
var createSquareFuncWithAdjustment = function(offset) {
return function(val) { return Math.round((val - offset) * 5 / 9); };
};
var fahrenheit = [0, 32, 45, 50, 75, 80, 99, 120];
fahrenheit.map(createSquareFuncWithAdjustment(32));
var SearchForm = function(e) {
return this instanceof SearchForm ? (this.$el = $(e),
void this.$el.on("submit", $.proxy(this.handleSubmit, this))) : new SearchForm(e)
};
SearchForm.prototype.handleSubmit = function(e) {
e.preventDefault();
var a = $.trim(this.$el.find("#search-input").val());
a && $(document).trigger("search", a)
}
;
@seb-thomas
seb-thomas / walkingCircle.js
Created November 17, 2016 22:58
Walking circle for Living Map, uses location API and D3
L.WalkingCircleLayer = (L.Layer ? L.Layer : L.Class).extend({
initialize: function() {
this._prefix = this._prefixMatch(["webkit", "ms", "Moz", "O"]),
this._canvasPadding = 4,
this._isActive = !1
},
onAdd: function(t) {
var a = L.DomUtil.create("div", "leaflet-control-walkingcircle leaflet-bar leaflet-control");
this._link = L.DomUtil.create("a", "leaflet-bar-part leaflet-bar-part-single", a),
this._icon = L.DomUtil.create("span", "fa fa-location-arrow", this._link),
// Assumes a vertical sprite sheet
$icon-size: 18px;
.icon {
display: inline-block;
background-repeat: no-repeat;
background-image: url(../images/sprite.png);
width: $icon-size;
height: $icon-size;
background-size: $icon-size;
@seb-thomas
seb-thomas / inspect-fields.twig
Created February 3, 2016 16:31
Code for getting all field attr to entry
{% for fieldLayoutField in entry.getFieldLayout().getFields() %}
{# get the field Model from the fieldId #}
{% set field = craft.fields.getFieldById(fieldLayoutField.fieldId) %}
{# print the field handle and the field content #}
{{ field.handle | inspect }}
{% endfor %}
@seb-thomas
seb-thomas / _entry.twig
Last active January 12, 2016 09:48
Craft CMS template code for wrapping every 2 half width blocks in a row
{# Set outside of block iterator #}
{% set number_of_halves = 0 %}
{% for block in entry.casestudyModules %}
{# Full width block types #}
{% if block.type == "slider" %}
{% if block.slideImage | length %}
{% include 'modules/slider-module' %}
{% endif %}