Skip to content

Instantly share code, notes, and snippets.

View johanbrook's full-sized avatar
🌴

Johan Brook johanbrook

🌴
View GitHub Profile
var isSameDay = function (thisEntry, lastEntry) {
var endTime = moment('6:00am', 'h:mma');
if (lastEntry.isSame(thisEntry, 'day')) {
// Same day, but time has passed 6am since last click, in other words: new day
return !(thisEntry.isAfter(endTime) && lastEntry.isBefore(endTime));
} else if (lastEntry.isSame(thisEntry.subtract(1, 'days'))) {
// Last entry was yesterday, but after 6am, and this entry is before 6am, therefore within the same night
return thisEntry.isBefore(endTime) && lastEntry.isAfter(endTime);
}
@johanbrook
johanbrook / disable-hcr.js
Created October 6, 2015 07:58
Disable Hot Code Reload in Meteor with a settings variable (`DISABLE_AUTO_RELOAD`).
Meteor.startup(function() {
if (Meteor.settings && Meteor.settings.public && Meteor.settings.public.DISABLE_AUTO_RELOAD) {
Meteor._reload.onMigrate(function(reloadFunction) {
return [false];
});
}
});
.use collections
posts:
pattern: 'posts/**.html'
sortBy: 'date'
reverse: true
.use branch('posts/**.html').use(
permalinks(pattern: 'writings/:title', relative: false)
)
@johanbrook
johanbrook / github.css
Created May 12, 2015 17:40
HighlightJS GitHub style
/*
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
*/
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
color: #333;
background: #f8f8f8;
@johanbrook
johanbrook / fixture
Last active August 29, 2015 14:15
Code tabs in Markdown.
<div class="code-tabs">
```objc
NSLog(@"Some string");
```
```swift
var sortedStrings = sorted(stringArray) {
$0.uppercaseString < $1.uppercaseString
}
<?php
$categories = get_terms("worktype", array(
"orderby" => "count",
"order" => "DESC"
));
function get_next_post_with_thumbnail($posts, $index) {
if($index == count($posts)) {
return null;
@johanbrook
johanbrook / jquery.scroll-stroke.js
Created November 25, 2014 23:09
jQuery plugin for drawing an SVG line while scrolling.
/*
jQuery plugin for drawing a svg line as you scroll.
@author Johan Brook, for Lookback (2014).
Options:
startAt: The reference point to start calculating from. Expects a selector.
speed: at which speed the line should draw.
offset: the offset of which the reference point should be.
@johanbrook
johanbrook / dolls.java
Created September 29, 2014 13:46
Recursive doll counter.
public static int recursiveDollCounter(Doll doll) {
if(doll.isCore()) {
return 0;
}
else {
doll.removeOuterLayer();
return recursiveDollCounter(doll) + 1;
}
}
@johanbrook
johanbrook / parseTimestamp.js
Last active August 29, 2015 14:06
Parse a timestamp or duration like `3h2m1s` to total seconds.
/*
* Parses a human readable duration on the form
* and return the total duration in seconds.
*
* @param {string} - Timestamp on the form XhYmZs. Unit
* parts are optional: 3h2s, 3m1s, 4h2m
* are all valid.
*/
function parseTimestamp(timestamp) {
I20140909-09:52:55.345(2) (lookback-intercom.js:17) Team with id: 6rQxyHw22iNM7cZqJ updated at Intercom.
I20140909-09:53:13.111(2)? Tue, 09 Sep 2014 07:53:13 GMT intercom.io Requesting [POST] users with data %o { user_id: 'mWabDbGhq8jYowvzv',
I20140909-09:53:13.112(2)? email: 'johan@johanbrook.com',
I20140909-09:53:13.113(2)? name: 'Dummy User8',
I20140909-09:53:13.113(2)? created_at: Tue Sep 09 2014 09:53:13 GMT+0200 (CEST),
I20140909-09:53:13.113(2)? sign_up_source: 'invite',
I20140909-09:53:13.114(2)? created_via: 'web',
I20140909-09:53:13.114(2)? companies: [ { id: '6rQxyHw22iNM7cZqJ', pending_invitations: 0 } ] }
I20140909-09:53:14.297(2)? Tue, 09 Sep 2014 07:53:14 GMT intercom.io Recieved response {"intercom_id":"540eb1ea2c1d79704a000b05","email":"johan@johanbrook.com","user_id":"mWabDbGhq8jYowvzv","name":"Dummy User8","created_at":1410249193,"last_impression_at":1410249194,"custom_data":{"sign_up_source":"invite","created_via":"web"},"social_profiles":[],"location_data":{"city_name":"Gothen