Skip to content

Instantly share code, notes, and snippets.

View shinnn's full-sized avatar
🍉

shinnn shinnn

🍉
View GitHub Profile
@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);
@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 / 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 / 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 / deleteEmptyFiles.pde
Last active December 10, 2015 01:58
Delete all empty log files, for Processing
/*
* Delete all empty log files,
* which are created when the "flush()" method isn't used correctly.
*/
import java.io.File;
File[] files = new File(sketchPath("log")).listFiles();
int deleted = 0;
for(File elm : files){
<?php
function cssSprite($singleWidth, $singleHeight, $verticalNum, $horizontalNum, $elementNum){
echo " style='background:";
echo -floor($elementNum * ceil(1 / $verticalNum)) * $singleWidth, "px ";
echo -$elementNum % $horizontalNum * $singleHeight, "px ";
echo "url(******.jpg) no-repeat;'";
}
?>
@shinnn
shinnn / floatVersion.php
Last active December 10, 2015 22:28
Version checker in PHP (for an environment in which get_browser() is unavailable) / You can properly convert a string of version number, often including two or more periods, into a php-readable floating point number.
<?php
$agent = getenv('HTTP_USER_AGENT');
function getVersion($req){
global $agent;
preg_match(
"/(?<=".$req."[^0-9\.])([0-9]+)([0-9\._]+?)(?=[^0-9\._]|$)/i",
$agent,
$matchedStringsArr
@shinnn
shinnn / _cssSprite.horizontalHover.scss
Last active December 10, 2015 22:29
Setting CSS sprite and :hover effect, in Sass
// background.jpg
//
// +------+------+
// |#aaa |#aaa |
// | |:hover|
// +------+------+
// |#bbb |#bbb |
// | |:hover|
// +------+------+
// |#ccc |#ccc |
@shinnn
shinnn / playlist.js
Last active December 11, 2015 07:39
Creating playlist on album name of itlp file, in iTunes LP (http://www.apple.com/itunes/lp-and-extras/)
var mainPlaylist = iTunes.createTempPlaylist();
(function(){
//location.host returns "persistentid-***"
var hostPersistentID = location.host.split("-")[1];
var tmpArr = iTunes.findTracksByTextFields({
album : iTunes.findTrackByPersistentID( hostPersistentID ).album
});
/*
ArduinoなどのUSBデバイスを繋いでいる状態でこれを実行すると、
デバイス名がクリップボードにコピーされる
そのまま Quartz Composer の、Kineme Serial Inputの Device 欄にペーストすると
Quartz Composerでのシリアル通信が始まる
*/
import java.awt.datatransfer.Clipboard;