Skip to content

Instantly share code, notes, and snippets.

View shinnn's full-sized avatar
🍉

shinnn shinnn

🍉
View GitHub Profile
@shinnn
shinnn / loadjquery.jade
Created June 10, 2013 10:29
Loading CDN-hosted jQuery with triple fallbacks in Jade template Engine
mixin loadJQuery(version)
script(src='https://ajax.googleapis.com/ajax/libs/jquery/#{version}/jquery.min.js')
- var jQueryFallbacks = [];
- jQueryFallbacks[0] = 'http://code.jquery.com/jquery-' + version + '.min.js';
- jQueryFallbacks[1] = 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-' + version + '.min.js';
- jQueryFallbacks[2] = 'js/jquery' + (version.charAt(0) === '1'? '1': '') +'.js';
each url in jQueryFallbacks
script.
@shinnn
shinnn / quicklook.txt
Last active December 17, 2015 13:29
The list of Quick Look plugins currently I use
QuickLookJSON.qlgenerator
CC_QL.qlgenerator
QLStephen.qlgenerator
QLColorCode.qlgenerator
QLMarkdown.qlgenerator
ScriptQL.qlgenerator
DICOMQuickLook.qlgenerator
ProcessingQL.qlgenerator
Archive.qlgenerator
GBQLGenerator.qlgenerator
// Fork from Chromium's 'Bufferloader' class
// http://chromium.googlecode.com/svn/trunk/samples/audio/doc/loading-sounds.html
function BufferLoader(audioContext, urlList, callback){
this.context = audioContext;
this.urlList = urlList;
this.onload = callback;
this.bufferList = [];
this.loadCount = 0;
}
@shinnn
shinnn / addEvent.js
Last active December 12, 2015 09:09
var addEvent;
if('addEventListener' in window){
addEvent = function(elm, eventType, func){
elm.addEventListener(eventType, func, false);
};
}else if('attachEvent' in window){ // IE
addEvent = function(elm, eventType, func){
elm.attachEvent('on'+eventType, function(){ func.apply(elm); });
};
}
/*
ArduinoなどのUSBデバイスを繋いでいる状態でこれを実行すると、
デバイス名がクリップボードにコピーされる
そのまま Quartz Composer の、Kineme Serial Inputの Device 欄にペーストすると
Quartz Composerでのシリアル通信が始まる
*/
import java.awt.datatransfer.Clipboard;
@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
});
@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 / 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
<?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 / 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){