Skip to content

Instantly share code, notes, and snippets.

View jonmaim's full-sized avatar
🌍
Back in Europe!

Jon Maim jonmaim

🌍
Back in Europe!
View GitHub Profile
@jonmaim
jonmaim / zip.php
Last active January 22, 2024 00:19
PHP script to remotely create zip archives of your FTP
<?php
/*
*
* This script will backup your web site by remotely archiving all files on the root FTP directory.
* It will work even if your web server is memory limited buy splitting zips in several arhive files it they are too many files.
* All zip files will be stored in a directory called temporary which must be writable.
*
* How to use it:
* - Place the script at the root of your FTP.
@jonmaim
jonmaim / check_disk_usage.js
Last active June 6, 2022 19:03
NodeJS: check disk usage and output remaining space if under 10%
var disk = require('diskusage');
disk.check('/', function(err, info) {
function toGB(x) { return (x / (1024 * 1024 * 1024)).toFixed(1); }
var percentAvailable = ((info.available / info.total) * 100);
if (percentAvailable < 10) { console.log('Warning only ' + toGB(info.available) + 'GB (' + percentAvailable.toFixed(1) + '%) space available!'); }
});
@jonmaim
jonmaim / csv2js.js
Last active November 23, 2020 11:00
Function takes a CSV (header + data) string as input and gives back a JS object.
// Start from https://gist.github.com/iwek/7154578#file-csv-to-json-js
// and fix the issue with double quoted values
function csvTojs(csv) {
var lines=csv.split("\n");
var result = [];
var headers = lines[0].split(",");
for(var i=1; i<lines.length; i++) {
var obj = {};
@jonmaim
jonmaim / import_migration.json
Created June 22, 2020 15:48
Migration to Android X
{
"android.arch.core.executor.AppToolkitTaskExecutor": "androidx.arch.core.executor.AppToolkitTaskExecutor",
"android.arch.core.executor.ArchTaskExecutor": "androidx.arch.core.executor.ArchTaskExecutor",
"android.arch.core.executor.DefaultTaskExecutor": "androidx.arch.core.executor.DefaultTaskExecutor",
"android.arch.core.executor.JunitTaskExecutorRule": "androidx.arch.core.executor.JunitTaskExecutorRule",
"android.arch.core.executor.TaskExecutor": "androidx.arch.core.executor.TaskExecutor",
"android.arch.core.executor.TaskExecutorWithFakeMainThread": "androidx.arch.core.executor.TaskExecutorWithFakeMainThread",
"android.arch.core.executor.testing.CountingTaskExecutorRule": "androidx.arch.core.executor.testing.CountingTaskExecutorRule",
"android.arch.core.executor.testing.InstantTaskExecutorRule": "androidx.arch.core.executor.testing.InstantTaskExecutorRule",
"android.arch.core.internal.FastSafeIterableMap": "androidx.arch.core.internal.FastSafeIterableMap",
@jonmaim
jonmaim / timezoneConversions.json
Created April 23, 2020 10:02 — forked from danderson00/timezoneConversions.json
Convert Windows time zone names to IANA names. Derived from http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml using the `001` territory for each zone.
{
"Dateline Standard Time": "Etc/GMT+12",
"UTC-11": "Etc/GMT+11",
"Aleutian Standard Time": "America/Adak",
"Hawaiian Standard Time": "Pacific/Honolulu",
"Marquesas Standard Time": "Pacific/Marquesas",
"Alaskan Standard Time": "America/Anchorage",
"UTC-09": "Etc/GMT+9",
"Pacific Standard Time (Mexico)": "America/Tijuana",
"UTC-08": "Etc/GMT+8",
@jonmaim
jonmaim / qs.js
Created December 8, 2012 10:51
Generate query string for angular.js
/* Converts an object into a key/value par with an optional prefix. Used for converting objects to a query string */
var qs = function(obj, prefix){
var str = [];
for (var p in obj) {
var k = prefix ? prefix + "[" + p + "]" : p,
v = obj[k];
str.push(angular.isObject(v) ? qs(v, k) : (k) + "=" + encodeURIComponent(v));
}
return str.join("&");
}

Keybase proof

I hereby claim:

  • I am jonmaim on github.
  • I am jonmaim (https://keybase.io/jonmaim) on keybase.
  • I have a public key ASAgVwTEflcw0rY7tZrrAsdtyV1mEFhD2twakOr-WtShMgo

To claim this, I am signing this object:

@jonmaim
jonmaim / iterate_dbs.js
Last active February 13, 2019 07:22
Mongo shell: iterate over all dbs
/* switch to admin database and get list of databases */
db = db.getSiblingDB("admin");
dbs = db.runCommand({ "listDatabases": 1 }).databases;
/* iterate through each database and get its collections */
dbs.forEach(function(database) {
print(database.name);
db = db.getSiblingDB(database.name);
cols = db.getCollectionNames();
@jonmaim
jonmaim / get_commenters_from_last_post.js
Created December 16, 2018 15:48
Get the commenters list from your last Steem post
'use strict';
/* to be filled up */
const selfName = 'jonmaim';
const postingWif = 'xxx';
const steem = require('steem');
const timeout = (ms) => new Promise(resolve => setTimeout(resolve, ms));
@jonmaim
jonmaim / bot1.js
Last active November 29, 2018 15:08
First steem voting bot
'use strict';
const steem = require('steem');
/* to be filled up */
const selfName = '';
const postingWif = '';
const eol = '\n';