Skip to content

Instantly share code, notes, and snippets.

View ROBERT-MCDOWELL's full-sized avatar

ROBERT MCDOWELL ROBERT-MCDOWELL

View GitHub Profile
@apk
apk / websock.sh
Created April 18, 2012 15:51
A web socket server as a bash script.
#!/bin/bash
# WebSocket shell, start & browse to http://<Host>:6655/
# Requires bash 4.x, openssl.
# Author: rootshell@corelogics.de (which isn't me, apk)
coproc d { nc -l -p 6656 -q 0; }
nc -l -p 6655 -q 1 > /dev/null <<-ENDOFPAGE
HTTP/1.1 200 OK
<html><head><script language="javascript">
var url = location.hostname + ':' + (parseInt(location.port) + 1);
@fetus-hina
fetus-hina / weeknumber2date.php
Created November 23, 2012 10:44
Calculate date by ISO-Week-Number (and wday)
<?php
function weekNumberToDate($year, $week, $wday = 1) {
// http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday
$correction = (int)gmdate('w', gmmktime(0, 0, 0, 1, 4, (int)$year)) + 3;
$yday = (int)$week * 7 + (int)$wday - $correction;
$time = gmmktime(0, 0, 0, 1, $yday, (int)$year);
return array((int)gmdate('Y', $time), (int)gmdate('n', $time), (int)gmdate('j', $time));
}
var_dump(weekNumberToDate(2008, 39, 6));
@fliptopbox
fliptopbox / string.compress.js
Created October 15, 2013 12:32
JavaScript String compression
/*
@fliptopbox
LZW Compression/Decompression for Strings
Implementation of LZW algorithms from:
http://rosettacode.org/wiki/LZW_compression#JavaScript
Usage:
var a = 'a very very long string to be squashed';
var b = a.compress(); // 'a veryāăąlong striċ to bečquashed'
@Sitwon
Sitwon / wget.sh
Created January 3, 2014 19:22
A very basic replacement for wget in pure Bash.
#!/bin/bash
wget() {
local PROTO=${1%%://*}
local NOPROTO=${1#*://}
local HOST=${NOPROTO%%/*}
local PORT=${HOST#*:}
[ "${HOST}" = "${PORT}" ] && PORT=80
HOST=${HOST%:*}
local URI=${NOPROTO#*/}
@thomasfr
thomasfr / autossh.service
Last active January 5, 2024 08:11
Systemd service for autossh
[Unit]
Description=Keeps a tunnel to 'remote.example.com' open
After=network.target
[Service]
User=autossh
# -p [PORT]
# -l [user]
# -M 0 --> no monitoring
# -N Just open the connection and do nothing (not interactive)
@Teaonly
Teaonly / yuv_canvas
Created May 16, 2014 03:31
Draw YUV in a HTML5's Canvas
function yuv2canvas(yuv, width, height, canvas) {
/*
canvas.width = width;
canvas.height = height;
*/
context = canvas.getContext("2d");
output = context.createImageData(width, height);
outputData = output.data;
yOffset = 0;
@ashrithr
ashrithr / kerberos_setup.md
Last active March 19, 2024 16:20
Set up kerberos on Redhat/CentOS 7

Installing Kerberos on Redhat 7

This installation is going to require 2 servers one acts as kerberos KDC server and the other machine is going to be client. Lets assume the FQDN's are (here cw.com is the domain name, make a note of the domain name here):

  • Kerberos KDC Server: kdc.cw.com
  • Kerberos Client: kclient.cw.com

Important: Make sure that both systems have their hostnames properly set and both systems have the hostnames and IP addresses of both systems in

@alumican
alumican / Timer.as
Created September 3, 2014 09:21
AS3 Timer based on getTimer
package util
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
import flash.utils.getTimer;
/**
* This is the timer class based on getTimer().
@carols10cents
carols10cents / javascript-to-rust-cheat-sheet.md
Last active October 28, 2023 07:57
JavaScript to Rust Cheat Sheet

JavaScript to Rust Cheat Sheet

The goal of this is to have an easily-scannable reference for the most common syntax idioms in JavaScript and Rust so that programmers most comfortable with JavaScript can quickly get through the syntax differences and feel like they could read and write basic Rust programs.

What do you think? Does this meet its goal? If not, why not?

Variables

JavaScript:

How I switched from mdadm to btrfs

After reading [this Ars Technica article][1], I decided that I wanted to start using btrfs on my home fileserver. It had been running for a few years with an mdadm raid-10 array, formatted with ext4, holding about 3.4 TB of data. I figured I would take advantage of some of the special capabilities of btrfs to perform the conversion in place. After some research, I formed my basic plan.

  • backup data to external drives
  • remove two of the drives from the mdadm raid-10
  • configure those two drive with a btrfs raid-0 filesystem
  • copy the data from the degraded mdadm raid-10 to the new btrfs raid-0
  • completely deactivate the mdadm raid-10