Skip to content

Instantly share code, notes, and snippets.

View mach3's full-sized avatar
🏠
Working from home

まっは mach3

🏠
Working from home
View GitHub Profile
@mach3
mach3 / getfeed.php
Created December 13, 2010 15:03
Get the feed informations using xpath.
<?php
$dom = @DOMDocument::loadHTMLFile( $url );
$xpath = new DOMXpath( $dom );
$query = "//link[ @rel='alternate' and ( @type='application/x.atom+xml' or "
. "@type='application/atom+xml' or @type='application/xml' or @type='text/xml' or "
. "@type='application/rss+xml' or @type='application/rdf+xml' ) ]";
$elements = $xpath->query( $query );
@mach3
mach3 / detect-feed.php
Created December 14, 2010 09:44
Cheep tip to detect atom or rss.
<?php
$dom = DOMDocument::load( $url );
// TRUE when RSS 1.0/2.0
$isRSS = $dom->getElementsByTagName("item")->length > 0;
// TRUE when Atom
$isAtom = $dom->getElementsByTagName("entry")->length > 0;
@mach3
mach3 / curl_get_contents.php
Created December 16, 2010 08:00
The cheapest example of curl for file_get_contents
<?php
function curl_get_contents( $url ){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec( $ch );
curl_close( $ch );
return $result;
@mach3
mach3 / jquery.togglepassword.js
Created January 17, 2011 18:45
Toggle and display password.
$.fn.extend({
togglePassword : function( config ){
option = $.extend({
"postfix" : "-text"
}, config );
sync = function(){
var i = this.type.toUpperCase() === "PASSWORD" ?
this.id + option.postfix :
this.id.replace( option.postfix, "" );
$( "#" + i ).val( $(this).val() );
@mach3
mach3 / anywhere.follow.js
Created May 7, 2011 09:09
@anywhereでフォローまわりを。
twttr.anywhere( function(tw){
var id_str, followMe;
id_str = "XXXXXXXXX";
followMe = function(){
if( !tw.isConnected() ){
tw.bind( "authComplete", followMe );
tw.signIn();
return;
}
tw.currentUser.isFollowing( id_str, function( f ){
@mach3
mach3 / MultiHashResult.js
Created May 7, 2011 11:29
Twitterの複数のハッシュタグの検索結果をマージする
var MultiHashResult = function( tags ){
var d, self, _onLoad, _onComplete, _reset ;
self = this;
d = {
api : "http://search.twitter.com/search.json",
callback : null,
tags : null,
loaded : 0,
results : null,
tweets : null,
@mach3
mach3 / hashchange.js
Created September 15, 2011 12:41
location.hashの変更イベントを受け取るためのもの。
/*!
* HashChange.js
* @version 1.0
* @author mach3
* @example
* var foo = new HashChange();
* foo.config({ onInit:myInitFunc, onChange:myChangeFunc, interval:100 });
* foo.start(); // When start to observe.
* foo.stop(); // When stop to observe.
*/
@mach3
mach3 / MY_Services_twitter.php
Created October 17, 2011 10:43
Servces_Twitterを拡張して定義ファイルを追加で読み込めるようにする。
<?php
require_once( "Services/Twitter.php" );
class MY_Services_twitter extends Services_twitter {
public function __construct(){
parent::__construct();
}
@mach3
mach3 / facebook_fangate.php
Created January 5, 2012 18:47
Fangate class for facebook.
<?php
/**
* Facebook fangate class
*
* @example
* $fangate = new Facebook_Fangate();
* $fangate->setSecret( $your_application_secret );
* $fangate->parse();
* $fangate->isLiked(); // true if the page is liked
@mach3
mach3 / getliked.php
Created January 9, 2012 11:30
ページがLikedかどうかを得るだけの簡単な関数
<?php
/**
* likedを得るだけの簡単な関数
*/
function getLiked(){
$signed_request = isset( $_POST["signed_request"] ) ? $_POST["signed_request"] : null;
$json = json_decode( base64_decode( array_pop( explode( ".", $signed_request ) ) ) );
if( isset( $json->page ) && isset( $json->page->liked ) ){
return $json->page->liked;