MongoDB shell:
> db.users.update({}, {$set : { subscribe : true }}, false, true)
> db.users.update({}, {$set : { subscribe : true }}, false, true)
MongoDB Shell:
> db.users.find({}, {email:1}).forEach(function(u) {print(u.email)})
<Bookstore> <Book> <ISBN>9781401309657</ISBN> <Name>The Last Letcture</Name> <Author>Randy Pausch</Author> </Book> </Bookstore>Code: Result:
[{'ISBN',"9781401309657"}, {'Name',"The Last Letcture"}, {'Author',"Randy Pausch"}]
repeat_words('a', 4); // output: 'aaaa'
Sometimes we will use
$('div:visible') // Does not use querySelectorAll()
to select something is visible, but it dose not utilize querySelectorAll()
so we can use
$('div').filter(':visible') // Uses it
to get high performance
See Also
http://tutorialzine.com/2011/06/15-powerful-jquery-tips-and-tricks-for-developers/var crypto = require('crypto'); console.log(crypto.createHash('md5').update('123').digest("hex")); // 202cb962ac59075b964b07152d234b70
簡而言之, 就是暫存整個Array的長度, 不要loop時每次都去取Array.length
See Also~$ sudo gedit /etc/apt/sources.list
# Reverse Proxy ProxyRequests Off <Proxy *> Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 Allow from 1.2.3.0/23 </Proxy> ProxyPass /chat/ http://mydomain.com:1234/ ProxyHTMLURLMap http://mydomain.com:1234 /chat/ <Location /msg/> ProxyPassReverse / # ProxyHTMLEnable if mod_proxy_html version >= 3.1 else SetOutputFilter # ProxyHTMLEnable On SetOutputFilter proxy-html ProxyHTMLURLMap / /chat/ # RequestHeader unset Accept-Encoding </Location>
var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8888, "127.0.0.1"); console.log('Server running at http://127.0.0.1:8888/');
~$ node HelloWorld.js
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 10.10 Release: 10.10 Codename: maverick
$ easy_install pip
Pip: http://pypi.python.org/pypi/pip
python setup.py install
$ pip install *package*
$ pip freeze | grep 'Django'
Django==1.5.1
Or
$ python Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> django.VERSION (1, 3, 0, 'final', 0)
Or
python -c "import django; print(django.get_version())"
#if TARGET_IPHONE_SIMULATOR // It's running on the simulator 目前跑在模擬器上 #else // Running on Actual Device 在實機上跑 #endif
NSDate *now = [NSDate date]; NSTimeInterval interval = [now timeIntervalSince1970]; NSLog(@"%@", now); // Date NSLog(@"%f", interval); // Date to Timesatmp NSLog(@"%@", [NSDate dateWithTimeIntervalSince1970:interval]); // Timestamp to Date
if(typeof String.prototype.trim !== 'function') { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } }
"We don't well support any IE browsers as that is killing all of the web engineers' time." -- GuruDigger
#import <QuartzCore/QuartzCore.h> txtView.layer.cornerRadius = 5;
%(python) %F
$ sudo apt-get install pwgen
$ pwgen
ohp1Shei Keiwohr9 nahThe8a Gie6Fiev xie0Un0v phi0GaiL Ie2quufo angie6Qu sahgoh6U Rubaot4o iphei1Ki tah2uChe oP9uong7 aixieJ0i Yachae6e chipa6In Reem3ahM ohda2Cei Eib5ohno gieLa0ze uighoo6X Shoom1Ee Goope5sh Viewah1a Jaito1oo chua9kiD du4eiP3y yohlie4T oc8oPhez Fu1quo0x bei1eaGh thahqu3K Zeila2ai Aosho2ag fie5aiV8 ooKejiv0 Ieb2kait eeg3Xoh0 quaete7E Shoo5eix iej2Iehe kee1Ohyu jeuDae9z eeShoh8j Ieth8Hai Queinai8 Zuce3ahb Oqu7ohd6 Thohtei0 aeT0ieth zur6teoZ doh0Oon2 Kooj1Lee uiDoh3jo ohHaiw1r uhet0eiX Jolei3do to8Thohh Lohmook0 fohH3jei pah1uRae HioTie4e jequ0Iet AhM5ieSo Voo3uTah Woo4eith Kai1aeth oazu1oT3 Toovah2e Aiz1uing yeiph8Ze Ayoo0po3 Gohqu3zu yohXesh4 pooXai7j zoo6de7E jicoo2oF uo5iez0U ieS7eeYe peFah4ph eihuoTh7 kooPh4ei Fat6aong re6Axai7 gieNg2ae omaeHee3 Shai3xep yin5aaJu Zuy3aaho ci3aiH1o aefo5aeW Sei3Phuu cu2wuaZu uu5ReeCo ohNgav5g OhLe9pha aPei4Iep Xae3Gefu fu8Wixae eox2Duuk Isahcie6 eegai7Mu Reibohj6 noh7AhL4 ea5Thae1 vongoh3W Eey7Uz9h ael4ooBu Lai2iuj2 iaSheap3 Alae8ao3 ee1Aetha reilaX8O Eenohj2y shee7Or9 uGh4eino Ohyot0mo iShuad9t kei0Eeko iequie8E nooN2kia ahn5kooH eizaa2Pi Aeth1aof Xalo3ohS Aoquuv2L Aij3pho0 Dah7ooF4 ohwa5ohY daf7JauT Ieko6bih Oox7ieko lain8Eil xe7Af8ei biepooX0 ju8Ied8A zagol7Qu EeM2etio eeW3ahno Chae5pho Nid0ceiz vie5Goo5 eW3ahbei Eik4thao Aer9Dini oos8Eeho fi4aBi2R aid2Chei Oob1Eipu iiJie1sh xeiDoo4o Amuu8bah sheiP9oh AeguGae9 iChee2oh Gah2yahy ZaiPh9Ah Pek0hahj BieM4ahs ooS6chah
$ apt-get install apache2 $ apache2 -v $ a2emod $ /etc/init.d/apache2 restart $ apt-get install php5 $ php -v $ apt-get install mysql-server $ mysql -u root -p Enter Password: mysql> select version(); $ apt-get install php5-mysql $ vim /var/www/phpinfo.php $ apt-get install phpmyadmin $ apt-get install vsftpd Mount /var/www $ groupadd webadmin $ useradd -mG webadmin --shell /bin/bash newUser $ passwd newUser $ chgrp -R webadmin /var/www/website $ chmod 775 /var/www/website $ chmod -R g+s /var/www/website $ mount --bind /var/www /home/newUser/www
NSPredicate *predicate = [NSPredicate predicateWithFormat: [NSString stringWithFormat:@"(firstName like '%@')", @"Hank"]]; NSArray *items = [fetchedResultsController.fetchedObjects filteredArrayUsingPredicate:predicate]; for (NSManagedObject *o in items) { NSLog(@"%@", o); }
CGRect f = self.view.frame; NSLog(@"w=%f, h=%f", f.size.width, f.size.height); NSLog(@"x=%f, y=%f", f.origin.x, f.origin.y);
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; return row; }
typedef enum { UIKeyboardTypeDefault, UIKeyboardTypeASCIICapable, UIKeyboardTypeNumbersAndPunctuation, UIKeyboardTypeURL, UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, UIKeyboardTypeNamePhonePad, UIKeyboardTypeEmailAddress, UIKeyboardTypeDecimalPad, UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable } UIKeyboardType;
MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
- (void)viewDidLoad { [self.textField becomeFirstResponder]; [super viewDidLoad]; }
- (void)enableKeyboard { [self.textField becomeFirstResponder]; } - (void)viewDidLoad { [self performSelector:@selector(enableKeyboard) withObject:nil afterDelay:.3]; [super viewDidLoad]; }
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }
-(void) instanceMethod:(NSString *)param; +(void) classMethod:(NSString *)param;
object.methodName(params);
@interface MyClass : NSObject { }
@interface MyViewController : UIViewController { }
最近瘋狂愛上她。IU |
[tfInput becomeFirstResponder];
[tfInput resignFirstResponder];
// 宣告array NSMutableArray *words = [NSMutableArray array]; // 宣告dictionary NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: @"Title 01", @"title", @"Explain 01", @"explain", nil]; // 將dict新增至array裡 [words addObject:dict]; // print出dict中所有資料 for (id key in dict) NSLog(@"key: %@ value: %@", key, [dict objectForKey:key]); // print出Array中所有資料 for (NSInteger i=0; i < [words count]; i++) NSLog(@"%@", [words objectAtIndex:i]); // print Array有幾筆資料 NSLog(@"Words count : %i", [words count]);Result
lower_case_table_names = 2
targetViewController.hidesBottomBarWhenPushed = YES;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UIViewController *targetViewController = [[menuList objectAtIndex: indexPath.row] objectForKey:kViewControllerKey]; targetViewController.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:targetViewController animated:YES]; [targetViewController release]; }
rm -fdr ${HOME}/Library/Application\ Support/iPhone\ Simulator
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(doSomething) userInfo:nil repeats:NO];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [alert show]; [alert release];
$ pip install BeautifulSoup
<span class="t18red"> 55138690</font>
看自己一年半前寫了一篇Java的文章 :
[Java] 計算自己已經活了幾天 calculate your age in days
最近都在寫Python, 就想說用Python也來寫一個, 還蠻簡單的。
Python版
Result
你已經活了 9479 天Java版
跟Java版比起來真的是簡潔太多了。"改天我們去..."
"有機會我一定要..."
>>> datetime.now() datetime.datetime(2011, 1, 11, 16, 19, 5, 211588) >>> datetime.now().isoformat() '2011-01-11T16:20:06.161541' >>> datetime.strftime(datetime.now(), '%Y-%m-%d') '2011-01-11' >>> datetime.strptime(datetime.now().isoformat(), '%Y-%m-%dT%H:%M:%S.%f') datetime.datetime(2011, 1, 11, 16, 24, 18, 411861)
<script type="text/javascript"> jQuery("a").each(function(index) { var r = new RegExp("^http://whhnote"); if (!r.test(jQuery(this).attr('href'))) { jQuery(this).attr('target', '_blank'); } }); </script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
.breadcrumbs{ padding:5px 5px 5px 0; margin:0;font-size:95%; line-height:1.4em; border-bottom:4px double #cadaef; }
<!-- breadcrumb --> <b:if cond='data:blog.homepageUrl == data:blog.url'> <b:else/> <b:if cond='data:blog.pageType == "item"'> <div class='breadcrumbs'> Browse » <a expr:href='data:blog.homepageUrl'>Home</a> » <b:if cond='data:post.labels'><b:loop values='data:post.labels' var='label'> <a expr:href='data:label.url' rel='tag'><data:label.name/></a> <b:if cond='data:label.isLast != "true"'> , </b:if> </b:loop> </b:if> » <data:post.title/> </div> </b:if> </b:if> <!-- breadcrumb -->
有時候抓出來的中文unicode字串像這樣 \u55ae\u8eca
結果找一堆資料, 試了unicode, encode, decode都試不出來
結果昨晚就到Stack Overflow去問問看, 果然有一堆好心人幫忙回答
沒想到只要unicode-escape就解決了
str = '\u55ae\u8eca' # It mean '單車'
print str.decode('unicode-escape')
See Also
How to convert utf-8 string to big5 with python? - Stack Overflowfrom datetime import datetime, timedelta created_at = 'Tue Jan 04 05:27:30 +0000 2011' utc_offset = '28800' # +0800 60 * 60 * 8 created_at = datetime.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y') local_time = created_at + timedelta(seconds = int(utc_offset)) print created_at print local_time