Skip to content

Instantly share code, notes, and snippets.

@akonwi
akonwi / production_db
Created May 22, 2013 04:02
Create production database locally in rails
Run in command line:
RAILS_ENV=production rake db:create db:schema:load
@akonwi
akonwi / gist:6002004
Created July 15, 2013 17:59
Secure copy over ssh
## Download
scp user@remote_host:remote_file local_file
## Upload
scp local_file user@remote_host:remote_file
# With these tasks you can:
# - dump your production database and save it in shared_path/db_backups
# - download most recent backup
namespace :db do
task :backup_name, :roles => :db, :only => { :primary => true } do
now = Time.now
run "mkdir -p #{shared_path}/db_backups"
backup_time = [now.year,now.month,now.day,now.hour,now.min,now.sec].join('-')
set :backup_file, "#{shared_path}/db_backups/#{application}-snapshot-#{backup_time}.sql"
end
$('#export').on('click', e => {
e.preventDefault();
tableToExcel('table', 'Servers');
})
var tableToExcel = (function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function (s) { return window.btoa(window['unescape'](encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) }
# Public: Execute a git command.
#
# options - An {Object} with the following keys:
# :args - The {Array} containing the arguments to pass.
# :cwd - Current working directory as {String}.
# :options - The {Object} with options to pass.
# :stdout - The {Function} to pass the stdout to.
# :exit - The {Function} to pass the exit code to.
#
# Returns nothing.
gitStagedFiles = (repo, stdout) ->
files = []
gitCmd
args: ['diff-index', '--cached', 'HEAD', '--name-status', '-z']
cwd: repo.getWorkingDirectory()
stdout: (data) ->
files = _prettify(data)
stderr: (data) ->
# edge case of no HEAD at initial commit
if data.toString().includes "ambiguous argument 'HEAD'"
git.cmd = (args, options={}) ->
new Promise (resolve, reject) ->
output = ''
try
new BufferedProcess
command: atom.config.get('git-plus.gitPath') ? 'git'
args: args
options: options
stdout: (data) -> output += data.toString()
stderr: (data) -> reject data.toString()
gitAddAllCommitAndPush = (repo) ->
git.add repo,
exit: ->
new GitCommit(repo, andPush: true)
git.add(repo).then -> GitCommit(repo, andPush: true)
module.exports = (func) ->
xs = []
curry = (x) ->
if x
xs.push x
curry
else
xs = [0] if xs.length is 0
func.apply null, xs