Skip to content

Instantly share code, notes, and snippets.

View ashcox's full-sized avatar

Ash Cox ashcox

View GitHub Profile
@ashcox
ashcox / Door.cs
Last active June 20, 2018 12:59
This door is not in use conumdrum
public class Door {
public Door(bool closed, bool hasNotInUseSign) {
this.InUse = closed;
this.HasNotInUseSign = hasNotInUseSign;
}
public State State => this.GetState();
private State GetState() {
if (InUse && !HasNotInUseSign) {
@ashcox
ashcox / tree.pl
Created January 11, 2018 14:49
Perl script to output a directory listing
#!/usr/bin/env perl
$no_of_args = @ARGV;
$expand_size = 5;
$max_width = 10;
if(($no_of_args == 0) || ($no_of_args == 2))
{
print "ERROR: Insufficient argument\n";
goto help;
#!/bin/bash
DIRECTORY=$1
DIRECTORY="${DIRECTORY%/}";
echo $DIRECTORY
echo "tarring up the following directory /web/htdocs/$DIRECTORY"
tar -cvpf "/web/htdocs/$DIRECTORY/$DIRECTORY.`date -u +%Y-%m-%d.%H.%M.%S`.tar" "/web/htdocs/$DIRECTORY/" > /dev/null
if [ ! -d "/web/htdocs/backups/$DIRECTORY" ]; then
@ashcox
ashcox / gist:8c7c87f2fffc9cddd879977f40ce231f
Created May 2, 2017 12:58 — forked from davidmerrick/gist:b9a8e5596db8cc98436d
jQuery: simulate form post from page
function post(path, params, method) {
method = method || "post"; // Set method to post by default if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
@ashcox
ashcox / gist:ff074c33829b0d17b94d69c87f37bd16
Created December 21, 2016 10:59 — forked from brainsik/gist:4280136
A simple way for Python cron tasks to exit if another process is currently running. Does not use a pidfile.
import os
import subprocess
import shlex
def bail_if_another_is_running():
cmd = shlex.split("pgrep -u {} -f {}".format(os.getuid(), __file__))
pids = subprocess.check_output(cmd).strip().split('\n')
if len(pids) > 1:
pids.remove("{}".format(os.getpid()))
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Bar Test</title>
<style type="text/css">
body {
font-family: Helvetica, sans-serif;
}
@ashcox
ashcox / 0_reuse_code.js
Created December 31, 2015 07:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ashcox
ashcox / delete-lines-from-file.pl
Last active December 15, 2015 11:06
Perl - Remove lines from filename
perl -ni -e 'print unless $. == 1' [filename]
@ashcox
ashcox / install-node-js.txt
Last active October 24, 2017 10:17
Install Node JS
sudo apt-get install npm
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
node -v
v5.0.0