Skip to content

Instantly share code, notes, and snippets.

View saibotsivad's full-sized avatar
💖
JavaScript

Tobias Davis saibotsivad

💖
JavaScript
View GitHub Profile

Context

Github Pages only supports redirects via Jekyll's ruby gem, which creates static HTML files with a <meta http-equiv="refresh" in the <head>.

Problem

If you run a JavaScript site that uses hash fragments (aka, site.com/#!/page) search engines may not be able to index the content. (See noddity as a blog framework that uses hash fragments but serves static files.)

General Solution

@saibotsivad
saibotsivad / controller.js
Last active August 29, 2015 14:10
Testing in Angular.js
angular.module('myMod', []).controller('MyCtrl', function($scope) {
$scope.var = 'hello';
$scope.thing = 'before';
$scope.change = function(word) {
$scope.var = word;
};
$scope.$watch('var', function() {
$scope.thing = 'after';
})
});
@saibotsivad
saibotsivad / days-between-dates.js
Last active August 29, 2015 14:15
An angular filter calculating the the days between two dates.
angular.module('eds.daysBetweenDates', []).filter('daysBetweenDates', function() {
return function(startDate, endDate) {
if (startDate && endDate) {
var start = moment(startDate).hour(0).minute(0).second(0).millisecond(0);
var end = moment(endDate).hour(0).minute(0).second(0).millisecond(0).add('day', 1);
return moment(end).diff(start, 'days')
} else {
return 0;
}
}
@saibotsivad
saibotsivad / request-from-server.js
Last active August 29, 2015 14:15
Example Angular.js use of the simple-request-caching module
angular.module('requestFromServer', [ 'simpleRequestCaching' ]).factory('requestFromServer', function($http, simpleRequestCaching) {
return new simpleRequestCaching({
cacheMillis: 1000 * 60, // one minute cache
request: function(params) {
return $http.get('/api/data', params)
}
})
})
@saibotsivad
saibotsivad / 404.html
Last active August 29, 2015 14:16
Cryptographically strong website applications
<!DOCTYPE html>
<html>
<head>
<title>404</title>
</head>
<body>
<h1>404'd!</h1>
</body>
</html>
@saibotsivad
saibotsivad / example.js
Last active August 29, 2015 14:18
Chain of promises split apart and recombined
Promise.all(getSomePromises)
.then(doSomeAction)
.then(doSomeOtherAction)
.then(function(data) {
return Promise.all([
Promise.all(data.filter(subsetOne).map(turnIntoPromises))
.then(doActionOne)
.then(doActionTwo),
Promise.all(data.filter(subsetTwo).map(turnIntoPromises))
.then(doActionThree)
@saibotsivad
saibotsivad / package.json
Created May 9, 2015 03:30
Base package.json setup
{
"name": "PROJECT_NAME",
"description": "",
"version": "0.0.2",
"author": "Jeff Barczewski <[email protected]>",
"repository": {
"type": "git",
"url": "http://github.com/jeffbski/PROJECT_NAME.git"
},
"bugs": {
@saibotsivad
saibotsivad / cheatsheet.md
Last active August 29, 2015 14:22
Markdown+Noddity Cheatsheet
  • Links to external websites are normal Markdown: [words](http://the-website.com)

    • [A](B) where A is the visible words, and B is the URL.
  • Links to internal Markdown pages are like this: [[folder/file-name.md|page name]]

    • [[A|B]] where A is the file path to the Markdown file, and B is the visible words.
  • Links to files are like this: [words](content/folder/file.pdf]

    • [A](content/B) where A is the visible words, B is the file path to the non-Markdown file.
  • Normal images are ![caption](http://the-website.com/folder/picture.jpg)

  • Images with relative paths are ![caption](/folder/picture.jpg)

@saibotsivad
saibotsivad / TestingJsoup.java
Last active August 29, 2015 14:28
JSoup 1.7.1 to 1.8.3 inconsistency
package com.saibotsivad.parser;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.Test;
import junit.framework.Assert;
@saibotsivad
saibotsivad / downthemall.sh
Created December 29, 2015 16:45
Download all these free math books!
#!/bin/bash
wget http://link.springer.com/content/pdf/10.1007/978-1-4757-1779-2.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4757-2103-4.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4684-9884-4.pdf
wget http://link.springer.com/content/pdf/10.1007/978-3-662-02945-9.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4612-9923-3.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4757-3828-5.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4684-9936-0.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4419-8566-8.pdf