Skip to content

Instantly share code, notes, and snippets.

View basuke's full-sized avatar
🍺
beer

Basuke Suzuki basuke

🍺
beer
View GitHub Profile
@basuke
basuke / playing.php
Created October 14, 2014 18:56
AlfredTweet patch. track informations should not be encoded to utf-8 at this point. Workflow seems to handle encoding correctly.
/**
* Description
* Accepts a player name as an argument and reads the values
* of the track name and artist for the currently playing track
* of that player
*
* @param $player - name of the player to read data from
* @return array - array of track name and artist for that player
*/
function get_tracks( $players )
@basuke
basuke / InvalidMimeGrammar.php
Created April 28, 2015 07:56
How to use RFC-invalid email addresses used by Japanese Cell carriers, DoCoMo and EZWeb using SwiftMailer
<?php
class InvalidMimeGrammar extends \Swift_Mime_Grammar {
/**
* Get the grammar defined for $name token.
* @param string $name exactly as written in the RFC
* @return string
*/
public function getDefinition($name)
{
/* 配列の配列からオブジェクトを検索しindexPathを返す */
- (NSIndexPath *)indexPathOfItem:(id)item {
__block NSIndexPath *indexPath = nil;
[groups_ enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSInteger row = [(NSArray *)obj indexOfObject:item];
if (row != NSNotFound) {
indexPath = [NSIndexPath indexPathForRow:row inSection:idx];
*stop = YES;
NSRange range;
NSString *str = @"";
if (type == PostTweetTypePublicRepyType) {
str = @"Reply";
range = NSMakeRange([str length], 0);
} else if (type == PostTweetTypeRetweetType) {
str = @"Retweeted";
range = NSMakeRange(0, 0);
} if (type == PostTweetTypePublicRepyToUserType) {
UIKIT_EXTERN NSString *const UIApplicationDidEnterBackgroundNotification __attribute__((weak_import));
UIKIT_EXTERN NSString *const UIApplicationWillEnterForegroundNotification __attribute__((weak_import));
def user_error_handler(func):
def wrapped(*args, **kwargs):
try:
response = func(*args, **kwargs)
except (InvalidUser,), e:
logger.error('%s: %s' % (func.__name__, str(e),))
response = HttpResponseNotFound('Not found')
return response
return wrapped
@basuke
basuke / console.php
Created December 16, 2010 07:29
colorize output of xterm terminals. console_out(array('Hello', 'green' => '"world"', '!'); echo "\n";
<?php
function console_styles() {
return array(
'heading1' => "\033[1;30;46m",
'heading2' => "\033[1;35m",
'heading3' => "\033[1;34m",
'option' => "\033[40;37m",
'command' => "\033[1;40;37m",
'error' => "\033[0;31m",
@basuke
basuke / LoadLocalizedFacebookConnect.html
Created January 20, 2011 01:28
How to load Facebook connect script localized for the page viewer.
<div id="fb-root">
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: '123456789xxxxxx',
status: true,
cookie: true,
xfbml: true
});
};
@basuke
basuke / Stickies Window positions
Created March 30, 2011 14:17
How to collect Stickies Window positions
tell application "Stickies"
activate
set w to {}
tell application "System Events"
tell application process "Stickies"
repeat with win in every window
set w to w & {position of win}
end repeat
@basuke
basuke / gist:1273222
Created October 9, 2011 03:08
UUIDのNSString生成
+ (NSString *)stringWithGUID {
CFUUIDRef uuid = CFUUIDCreate(nil);
NSString *str = (NSString*)CFUUIDCreateString(nil, uuid);
CFRelease(uuid);
return [str autorelease];
}