Skip to content

Instantly share code, notes, and snippets.

View shinnn's full-sized avatar
🍉

shinnn shinnn

🍉
View GitHub Profile
@shinnn
shinnn / unixUsbSerial.pde
Last active December 10, 2015 01:28
[for Mac OS X / Linux] unixUsbSerial() and unixUsbSerials(), functions to open USB serial ports easily in Processing
// Return single USB port's name
String unixUsbSerial(String device){
return unixUsbSerials(device, 1)[0];
}
// Return multiple USB ports' names
String[] unixUsbSerials(String device, int... num){
/* Parameter "device" can be "cu" or "tty".
* num[0] can be a number of ports required.
*/
@shinnn
shinnn / gotochapter.js
Last active October 11, 2015 05:57
goToChapter() Method on iTunes LP
iTunes.goToChapter = function(cNum){
//Note : iTunes.currentChapter starts at 1, NOT 0.
//If currently playing track has no chapter
if(this.currentChapter == 0 || ! cNum){
return;
}
var isPlaying = false;
if(this.waveform.waveformData){
@shinnn
shinnn / multisort.js
Last active October 11, 2015 05:37
Sort an array of objects by multiple fields
// ref: http://ituneslp.net/tutorials/itunescontrol
array.sortOn = function() {
for(var i=0 ; i < arguments.length; i++){
var field = arguments[i];
this.sort(function(a, b){
if(a[field] > b[field]){
return 1;
}
if(a[field] < b[field]){
@shinnn
shinnn / loadjquery.php
Last active October 8, 2015 07:38
Loading CDN-hosted jQuery with triple fallbacks in PHP
<?php
// ref: http://www.php.net/manual/ja/function.file-exists.php#79118
function getResource(){
$args_last_key = func_num_args() - 1;
$resource_urls = array_slice(func_get_args(), 0, $args_last_key);
// The last argument is a local file path.
$local_fallback = func_get_arg($args_last_key);