Skip to content

Instantly share code, notes, and snippets.

View jarrodbell's full-sized avatar

Jarrod Bell jarrodbell

View GitHub Profile
@jarrodbell
jarrodbell / makeReadable.js
Last active December 25, 2015 18:19
Convert byte array (or string) to a readable "\xFF" formatted string for any bytes outside the printable ascii range (32-127 decimal)
function makeReadable(bytes) {
var readable = "", i;
for (i = 0; i < bytes.length; i++) {
var byteVal = bytes.charCodeAt(i);
if (byteVal < 32 || byteVal > 127) {
readable += "\\x" + ("0" + byteVal.toString(16).toUpperCase()).slice(-2);
} else {
readable += bytes[i];
}
}
@jonschlinkert
jonschlinkert / markdown-cheatsheet.md
Last active September 3, 2024 08:34
A better markdown cheatsheet.
@jarrodbell
jarrodbell / hex.js
Last active December 14, 2015 22:38
JavaScript hex conversion snippets
// Convert 0-255 to hex byte:
String.fromCharCode(id)
// Convert 01-FF to hex byte:
String.fromCharCode(parseInt(id, 16))
// Convert hex byte to 0-ff:
id.charCodeAt(0).toString(16);
// Convert hex byte to 00-FF:
anonymous
anonymous / kal.js
Created August 1, 2012 12:46
iViewer - Append text from Crestron Kaleidescape module
CF.userMain = function(){
CF.watch(CF.JoinChangeEvent, "s19", doAppend) //this is the join in the iViewer SIMPL module, declare it in a page you never flip to
}
var appended = ""
function doAppend(join, value, tokens){
var regex = /\xFE\x02/;
if (regex.test(value)) {
appended += value.slice(2, value.length);
@jarrodbell
jarrodbell / gist:2144878
Created March 21, 2012 05:45
Basic Command Queuing for CommandFusion
/* Basic Command Queuing for CommandFusion
USAGE:
- First step: Replace the "SYSTEM NAME GOES HERE" text towards the end of the script with your actual system name as defined in the System Manager of your GUI project
- Next: Save this script into a .js file and add it to your GUI project via Project Properties > Script Manager.
- Ensure you are using iViewer4 (NOT CF iViewer, legacy product without JavaScript support)
- within button properties, add a JavaScript call such as:
CommandQueue.startCommand("StartDataGoesHere");
@jarrodbell
jarrodbell / gist:1789532
Created February 10, 2012 12:57
Toggle power state with feedback
/*
NOTE: Change "System Name" and "Feedback Name" to the correct info for your project first.
NOTE: Change "d1" to the digital join number of your power button.
NOTE: on your power button, set the javascript to: togglePower();
*/
var powerState = 0;
var powerStateRegex = /\x21\x01\x00\x00\x01(\x00|\x01)\x0D/;
@jarrodbell
jarrodbell / gist:1034969
Created June 20, 2011 01:03
PUT request using CF.request
var baseURL = "www.someurl.com";
var theURL = "/some/url?param=test";
var headerString = "\
PUT "+theURL+" HTTP/1.1\r\n\
Host: "+baseURL+"\r\n\
Accept-Encoding: gzip, deflate\r\n\
Content-Type: text/xml\r\n\
Content-Length: ";
@danielfaust
danielfaust / samsung_remote.py
Created May 30, 2011 04:12
Samsung TV Remote Control Python Script
import time
import socket
import base64
src = '192.168.1.2' # ip of remote
mac = '00-AB-11-11-11-11' # mac of remote
remote = 'python remote' # remote name
dst = '192.168.1.3' # ip of tv
app = 'python' # iphone..iapp.samsung
@geoffgarside
geoffgarside / gist:21000
Created October 30, 2008 13:25
MAC prefix to Vendor as a ruby array
[
['00-00-00', 'XEROX CORPORATION'],
['00-00-01', 'XEROX CORPORATION'],
['00-00-02', 'XEROX CORPORATION'],
['00-00-03', 'XEROX CORPORATION'],
['00-00-04', 'XEROX CORPORATION'],
['00-00-05', 'XEROX CORPORATION'],
['00-00-06', 'XEROX CORPORATION'],
['00-00-07', 'XEROX CORPORATION'],
['00-00-08', 'XEROX CORPORATION'],