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:4334849
Created December 19, 2012 06:35
Thinking through some export/import details.
var zip = new require('node-zip')()
us.map(blog.posts, function(post) {
if (post.is_attachment) {
console.log("Downloading: " + post.attachment_url)
request(post.attachment_url, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log("Saving " + post.folder + post.fileName)
zip.file(post.folder + post.fileName, body)
}
})
@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 / .gitconfig
Last active December 5, 2016 15:28
Mac .profile settings for bash
[color]
sh = auto
ui = auto
pager = true
[user]
name = User Name
email = email@domain.com
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
[core]
@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 / indentation.md
Last active December 1, 2016 15:13
The right way to indent

The "correct" way to indent

The issue of tabs-vs-spaces is a long and revered Flame War, so I don't think I'll be changing any minds with what I can write on the topic.

However, it's what I use in all the code that I personally write, and any projects I make public use it.

When to tab

@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: