Skip to content

Instantly share code, notes, and snippets.

View basuke's full-sized avatar
🍺
beer

Basuke Suzuki basuke

🍺
beer
View GitHub Profile
We couldn’t find that file to show.
class Boo(object):
pass
b = Boo()
def test(n):
b.n = n
m = 0 + n # int オブジェクトをコピー
print(n, b.n is m)
/* 配列の配列からオブジェクトを検索し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 / gen-security.php
Created April 20, 2011 10:08
Generate CakePHP configuration value for security, Security.salt and Security.cipherSeed.
<?php
$salt = genrandom(40);
$seed = genrandom(29, "0123456789");
echo "\tConfigure::write('Security.salt', '$salt');\n";
echo "\tConfigure::write('Security.cipherSeed', '$seed');\n";
function genrandom($len, $salt = null) {
if (empty($salt)) {