Skip to content

Instantly share code, notes, and snippets.

@skypanther
skypanther / foo.js
Created July 25, 2013 19:44
Within functions, arguments gives access to any parameters passed to the function. But it's a funky object, not a true array. I'm sure the following behavior is documented, but it caught me off-guard. So I thought I'd share.
var myFunction = function() {
if(typeof arguments[0] == 'function') {
arguments[0](); // throws error: [object Object] is not a function
// but this works
var cb = arguments[0];
cb();
}
};
myFunction(function() {
@skypanther
skypanther / anim.js
Last active April 4, 2016 08:56
Animate foreground color of a Titanium object, given a starting and ending hex value and a number of steps to take between.
function parseColor(color) {
// from http://www.bitstorm.org/jquery/color-animation/jquery.animate-colors.js
var match, triplet;
// Match #aabbcc
if (match = /#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(color)) {
triplet = [parseInt(match[1], 16), parseInt(match[2], 16), parseInt(match[3], 16), 1];
// Match #abc
} else if (match = /#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(color)) {
@skypanther
skypanther / keybase.md
Created February 8, 2017 19:35
keybase.md

Keybase proof

I hereby claim:

  • I am skypanther on github.
  • I am skypanther (https://keybase.io/skypanther) on keybase.
  • I have a public key whose fingerprint is 902C 1285 BB32 4F2E 0CF0 FBC5 2329 CA36 9FAB 9DE6

To claim this, I am signing this object:

@skypanther
skypanther / pushtest.js
Created April 20, 2017 12:59
GCM push test script
/*
Instructions
1. In the same directory where this js file exists, run `npm install gcm` (to install the required node module)
2. Get your GCM/FCM API Key from the Google APIs Console and paste it in place of "YOUR_GCM_API_KEY" below
2. You'll need your device's push token. You can get this by logging the token when your GCM-enabled app calls
the "success" callback after registering for push services. Paste it in place of "YOUR DEVICE_PUSH_TOKEN" below.
3. Run this with `node pushtest.js`
4. After a moment, you should get the push notification on your device
@skypanther
skypanther / Gruntfile.js
Last active May 3, 2017 11:48
Grunt - build your Titanium app and upload to Installr
var _ = require('underscore')._;
module.exports = function(grunt) {
grunt.initConfig({
settings: {
appName: 'YourAppName',
ppUuid: 'uuid', /* Provisioning profile UUID */
distributionName: 'cert_name', /* Distr. certificate name */
keystoreLocation: '/Users/path/to/android.keystore', /* path to keystore */
storePassword: 'keystore_password', /* keystore password */
@skypanther
skypanther / app.js
Created September 1, 2011 21:48
Draw gridlines in a Titanium window
// implement like this:
var window = Ti.UI.createWindow({
backgroundColor:'#fff'
});
// draw the gridlines first so your other elements stack on top of them
// without requiring you to set the z-index property of each
var grid = require('gridlines');
grid.drawgrid(10,window);
@skypanther
skypanther / base64EncodeAscii.js
Created July 26, 2017 13:16
Titanium, alternative base64encode function; not the author, sorry I don't recall the original source for this; also untested in recent Ti versions
// alternative to built-in base64 encode function, which has outstanding bugs
// alternatively, use:
// String(Ti.Utils.base64encode(theBlob)).replace(/(\r\n|\n|\r)/gm,"");
function Base64EncodeAscii(str) {
if (/([^\u0000-\u00ff])/.test(str)) {
throw 'String must be ASCII';
}
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1,
o2,
@skypanther
skypanther / encoder.java
Created February 11, 2017 19:58
scratch code for using the Talon SRX encoders
int circumferenceInInches = 123;
int pulsesPerRotation = 1000;
protected void function auto1() {
RobotDrive drive = RobotMap.driveSystemdrive;
CANTalon talon = RobotMap.driveSystemCANTalon1;
//Change control mode of talon, other options are Follower Mode or Voltage Compensation
talon.changeControlMode(ControlMode.Position);
//Select either QuadEncoder or Pulse Width / Analog, we want Quad
@skypanther
skypanther / slider.py
Created October 17, 2018 00:56
Trackbars (sliders) in OpenCV
'''
slider.py - Demonstrating a user of trackbars on OpenCV windows
Author: Tim Poulsen, github.com/skypanther
License: MIT
2018-10-15
Example usage:
python3 slider.py -i path/to/image.jpg
'''
@skypanther
skypanther / jetson_test.py
Created January 17, 2019 01:07
Test camera access on Jetson TX2
import cv2
def main():
cam = open_cam_usb(1, 1024, 768)
# cam = open_cam_onboard(1024, 768) # Use Jetson onboard camera
if cam.isOpened() is False:
print('failed to open camera')
exit()
while True: