Skip to content

Instantly share code, notes, and snippets.

View purpleidea's full-sized avatar

James purpleidea

View GitHub Profile
$brickdir = '/storage1';
$glusterdir = '/storage';
// if you only want to copy certain directories, specify them here
$directories = array('apt-mirror', 'apt-repo', 'downloads', 'torrents', 'storage');
$max_copies = 100; // concurrency
$file_size = 0; // total copied file size

Let's say you have a Bash shell script, and you need to run a series of operations on another system (such as via ssh). There are a couple of ways to do this.

First, you can stage a child script on the remote system, then call it, passing along appropriate parameters. The problem with this is you will need to manually keep the remote script updated whenever you change it -- could be a bit of a challenge when you have something to execute on a number of remote servers (i.e., you have a backup script running on a central host, and it needs to put remote databases in hot backup mode before backing them up).

Another option is to embed the commands you want to run remotely within the ssh command line. But then you run into issues with escaping special characters, quoting, etc. This is ok if you only have a couple commands to run, but if it is a complex piece of Bash code, it can get a bit unwieldy.

So, to solve this, you can use a technique called rpcsh -- rpc in shell script, as follows:

First, place th

@purpleidea
purpleidea / systemd-start-and-wait.go
Created May 4, 2018 13:51 — forked from ghedo/systemd-start-and-wait.go
Start a systemd unit and wait until it stops
package main
import "log"
import "os"
import "github.com/docopt/docopt-go"
import "github.com/godbus/dbus"
const target string = "org.freedesktop.systemd1";
const object string = "/org/freedesktop/systemd1";
@purpleidea
purpleidea / main.go
Created May 7, 2018 15:04 — forked from ast/main.go
Using epoll with go. Packages like fsnotify does not work with sysfs. Then you need epoll, poll or select.
package main
import (
"golang.org/x/sys/unix"
"log"
"os"
)
func main() {
file, err := os.Open("/sys/class/somefile")
@purpleidea
purpleidea / SMBDIS.ASM
Created June 30, 2018 02:10 — forked from 1wErt3r/SMBDIS.ASM
A Comprehensive Super Mario Bros. Disassembly
;SMBDIS.ASM - A COMPREHENSIVE SUPER MARIO BROS. DISASSEMBLY
;by doppelganger (doppelheathen@gmail.com)
;This file is provided for your own use as-is. It will require the character rom data
;and an iNES file header to get it to work.
;There are so many people I have to thank for this, that taking all the credit for
;myself would be an unforgivable act of arrogance. Without their help this would
;probably not be possible. So I thank all the peeps in the nesdev scene whose insight into
;the 6502 and the NES helped me learn how it works (you guys know who you are, there's no

In a terminal start a server.

$ python -m SimpleHTTPServer 8000

In another terminal set up the cgroups freezer.

@purpleidea
purpleidea / capslock_super_esc.md
Created November 18, 2018 01:30 — forked from bendavis78/capslock_super_esc.md
Mapping Caps Lock to simultaneous Esc and Super (Mod4)

Mapping Caps Lock to simultaneous Esc and Super (Mod4)

The CAPS key can be mapped to an escape key when pressed once, and a super (mod4) key when used in combination with other keys.

Create the file /usr/share/X11/xkb/symbols/custom_opts with the following:

// Make Caps an additional Escape
hidden partial modifier_keys
xkb_symbols "super_esc" {

key { [ Escape ] };

@purpleidea
purpleidea / readme.md
Created November 27, 2018 11:18 — forked from dominictarr/readme.md
statement on event-stream compromise

Hey everyone - this is not just a one off thing, there are likely to be many other modules in your dependency trees that are now a burden to their authors. I didn't create this code for altruistic motivations, I created it for fun. I was learning, and learning is fun. I gave it away because it was easy to do so, and because sharing helps learning too. I think most of the small modules on npm were created for reasons like this. However, that was a long time ago. I've since moved on from this module and moved on from that thing too and in the process of moving on from that as well. I've written way better modules than this, the internet just hasn't fully caught up.

@broros

otherwise why would he hand over a popular package to a stranger?

If it's not fun anymore, you get literally nothing from maintaining a popular package.

One time, I was working as a dishwasher in a restu

@purpleidea
purpleidea / copy.go
Created December 13, 2018 06:58 — forked from r0l1/copy.go
Copy a directory tree (preserving permissions) in Go.
/* MIT License
*
* Copyright (c) 2017 Roland Singer [roland.singer@desertbit.com]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: