Skip to content

Instantly share code, notes, and snippets.

View saibotsivad's full-sized avatar
💖
JavaScript

Tobias Davis saibotsivad

💖
JavaScript
View GitHub Profile
@saibotsivad
saibotsivad / gist:b73856885dcd42f52df1
Last active August 29, 2015 14:01
Timing test of Java's SimpleDateFormat
package com.edatasource.receipts.parser;
import org.junit.Test;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@saibotsivad
saibotsivad / SafeSimpleDateFormat.java
Created May 7, 2014 15:46
Make a thread safe SimpleDateFormat thingy.
package com.cedarsoftware.util;
import java.text.DateFormatSymbols;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
<?php
/*
Based on some other things I've seen online.
1: Edit the vars
2: Put on server somewhere accessible, e.g. your site folder as github.php
3: chmod +x github.php
4: Repo settings, add webhook to that url
*/
$LOCAL_ROOT = "/home/username/site.com";
@saibotsivad
saibotsivad / git-tips.md
Created June 2, 2014 14:32
Commonly used git commands

If you need to restructure your commit history (squash multiple commits into one, remove commits, etc.) use the command (where N is the number of commits to include in the restructure):

git rebase -i HEAD~N

E.g.,

git rebase -i HEAD~3
@saibotsivad
saibotsivad / mysql-tips.sql
Created June 2, 2014 16:30
Commonly used MySQL commands that I keep forgetting for some reason.
# insert from a select query
INSERT INTO table (column1,column2)
SELECT column1,column2
FROM ...
# dropping tables
DROP TABLE IF EXISTS tablename;
@saibotsivad
saibotsivad / index.js
Created July 23, 2014 01:51
Convert MediaWiki to markdown for noddity
'use strict'
var fs = require('fs')
var request = require('request')
var htmlparser = require("htmlparser2")
var toMarkdown = require('to-markdown').toMarkdown
var mkdirp = require('mkdirp')
if (process.argv[3] === undefined) {
console.log("Usage: node wikimedia-markdown-export.js [text file of all pages to export] [site domain]")
@saibotsivad
saibotsivad / change-docx.md
Last active August 29, 2015 14:06
Automatically converting DOC to MD

First convert DOC to DOCX using LibreOffice:

/Applications/LibreOffice.app/Contents/MacOS/soffice --invisible --convert-to docx file.doc

Then convert to Markdown using pandoc:

pandoc file.docx -f docx -t markdown -o file.md

Convert to Markdown, extracting the image files:

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;
}
}