Skip to content

Instantly share code, notes, and snippets.

@wookiecooking
Created November 21, 2013 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wookiecooking/7578264 to your computer and use it in GitHub Desktop.
Save wookiecooking/7578264 to your computer and use it in GitHub Desktop.
[Coffeescript/Javascript] Clones all of a users gists as repos
###
# Description #
Pulls all from a user as a git repos, and creates a markdown file with list.
# OSX Users will have issues due to limitations. #
run: ulimit -n 1024
more here: https://github.com/jacobrask/styledocco/issues/52
# Instructions #
npm install coffee-script
npm install async
npm install request
coffee app.coffee <username>
###
async = require("async")
request = require("request")
exec = require("child_process").exec
# How many pages
counter = [1, 2, 3]
# username example: wookiecooking
username = process.argv[2]
# Errors
errdor = (err, echo) -> if err then console.log err else console.log echo
# Git pull each gist and write description to a file via async
pull = (url) ->
request url, (err, res, c) ->
if not err and res.statusCode is 200
async.each JSON.parse(c), (gh) ->
exec "git clone " + gh.html_url + ".git "+gh.id, errdor
exec "echo \" - " + gh.id + " - " + gh.description + "\" >> list.md", errdor
# Run counter array
exec "echo \"#Gists\" >> list.md", errdor
async.eachLimit counter, 10000, (count) ->
pull "https://api.github.com/users/" + username + "/gists?page=" + count
/*
# Description #
Pulls all from a user as a git repos, and creates a markdown file with list.
# OSX Users will have issues due to limitations. #
run: ulimit -n 1024
more here: https://github.com/jacobrask/styledocco/issues/52
# Instructions #
npm install async
npm install request
node app.js <username>
*/
var async, counter, errdor, exec, pull, request, username;
async = require("async");
request = require("request");
exec = require("child_process").exec;
counter = [1, 2, 3];
username = process.argv[2];
errdor = function(err, echo) {
if (err) {
return console.log(err);
} else {
return console.log(echo);
}
};
pull = function(url) {
return request(url, function(err, res, c) {
if (!err && res.statusCode === 200) {
return async.each(JSON.parse(c), function(gh) {
exec("git clone " + gh.html_url + ".git " + gh.id, errdor);
return exec("echo \" - " + gh.id + " - " + gh.description + "\" >> list.md", errdor);
});
}
});
};
exec("echo \"#Gists\" >> list.md", errdor);
async.eachLimit(counter, 10000, function(count) {
return pull("https://api.github.com/users/" + username + "/gists?page=" + count);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment