you are here: codestackercodes [RSS] → tag twitter [RSS]

twitter-like input using css 3

textarea {  
	padding: 5px;  
	font-size: 15px;  
	text-shadow: 0px 1px 0px #fff;  
	outline: none;  
	-webkit-border-radius: 3px;  
	-moz-border-radius: 3px;  
	border-radius: 3px;  
	border: 1px solid #ccc;  
	-webkit-transition: .3s ease-in-out;  
	-moz-transition: .3s ease-in-out;  
}  

textarea:focus {  
	border: 1px solid #fafafa;  
	-webkit-box-shadow: 0px 0px 6px #007eff;  
	-moz-box-shadow: 0px 0px 5px #007eff;  
	box-shadow: 0px 0px 5px #007eff;  
}

fetching tweets with jquery

$(document).ready(function() {
    // Declare variables to hold twitter API url and user name

    var twitter_api_url = 'http://search.twitter.com/search.json';
    var twitter_user    = 'leozera';

    // Enable caching

    $.ajaxSetup({ cache: true });

    // Send JSON request

    // The returned JSON object will have a property called "results" where we find

    // a list of the tweets matching our request query

    $.getJSON(
        twitter_api_url + '?callback=?&rpp=5&q=from:' + twitter_user,
        function(data) {
            $.each(data.results, function(i, tweet) {
                // Uncomment line below to show tweet data in Fire Bug console

                // Very helpful to find out what is available in the tweet objects

                //console.log(tweet);


                // Before we continue we check that we got data

                if(tweet.text !== undefined) {
                    // Calculate how many hours ago was the tweet posted

                    var date_tweet = new Date(tweet.created_at);
                    var date_now   = new Date();
                    var date_diff  = date_now - date_tweet;
                    var hours      = Math.round(date_diff/(1000*60*60));

                    // Build the html string for the current tweet

                    var tweet_html = '<div class="tweet_text">';
                    tweet_html    += '<a href="http://www.twitter.com/';
                    tweet_html    += twitter_user + '/status/' + tweet.id + '">';
                    tweet_html    += tweet.text + '<\/a><\/div>';
                    tweet_html    += '<div class="tweet_hours">' + hours;
                    tweet_html    += ' hours ago<\/div>';

                    // Append html string to tweet_container div

                    $('#tweet_container').append(tweet_html);
                }
            });
        }
    );
});

post in twitter using rest_client

http://github.com/adamwiggins/rest-client

require "rubygems"
require "rest_client"

RestClient::Resource.new("http://twitter.com/statuses/update.json", :user => "user", :password => "pass").post :status => "Hello, there!"

jquery twitter

http://ralphwhitbeck.com/content/binary/twitter-json-jquery.html

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script>
	$(document).ready( function() {
	
		var url = "http://twitter.com/status/user_timeline/RedWolves.json?count=3&callback=?";
		$.getJSON(url,
        function(data){
			$.each(data, function(i, item) {
				$("img#profile").attr("src", item.user["profile_image_url"]); 
				$("#tweets ul").append("<li>" + item.text.linkify() + " <span class='created_at'>" + relative_time(item.created_at) + " via " + item.source + "</span></li>");
			});
        });
	});
	
	String.prototype.linkify = function() {
		return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
    return m.link(m);
  });
 }; 
  function relative_time(time_value) {
	  var values = time_value.split(" ");
	  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
	  var parsed_date = Date.parse(time_value);
	  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
	  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
	  delta = delta + (relative_to.getTimezoneOffset() * 60);
	  
	  var r = '';
	  if (delta < 60) {
	    r = 'a minute ago';
	  } else if(delta < 120) {
	    r = 'couple of minutes ago';
	  } else if(delta < (45*60)) {
	    r = (parseInt(delta / 60)).toString() + ' minutes ago';
	  } else if(delta < (90*60)) {
	    r = 'an hour ago';
	  } else if(delta < (24*60*60)) {
	    r = '' + (parseInt(delta / 3600)).toString() + ' hours ago';
	  } else if(delta < (48*60*60)) {
	    r = '1 day ago';
	  } else {
	    r = (parseInt(delta / 86400)).toString() + ' days ago';
	  }
	  
	  return r;
}
function twitter_callback ()
{
	return true;
}

</script>	
</head>
<body>
	<div id="tweets">
		<img id="profile">
		<ul></ul>
	</div>
</body>
</html>

jquery twitter plugin

from: http://www.tidbits.com.br/download/exemplos/jquery.twitter/jquery.twitter_original.zip

<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script type="text/javascript" src="jquery.twitter.js"></script>

<script type="text/javascript">
<!--//--><![CDATA[//><!--

	$(document).ready(function() {
		$("#twitter").getTwitter({
			userName: "leozera",
			numTweets: 5,
			loaderText: "Loading tweets...",
			slideIn: true,
			showHeading: true,
			headingText: "Latest Tweets",
			showProfileLink: true
		});
	});
//--><!]]>

</script>

<div id="twitter"></div>

count chars (like twitter)

http://woork.blogspot.com/2008/07/useful-tips-to-enrich-your-html-forms.html

function countChars(idElement){
max_chars = 20;
counter = document.getElementById(idElement);
field = document.getElementById('text').value;
field_length = field.length;

// Calculate remaining chars

remaining_chars = max_chars-field_length;
if(remaining_chars<=5){
	counter.style.color="#CC0000";
}
// Update the counter on the page

counter.innerHTML = remaining_chars;
}

// <input type="input" id="text" onKeyUp="javascript:countChars('counter_number')"/> <spam id="counter_number">20</spam>

post in twitter using curl

curl -u email:password -d status="hello world!" http://twitter.com/statuses/update.xml 

mac os reading twitter updates

require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'

content = ''
open('http://twitter.com/statuses/user_timeline/peepcode.rss').each { |i| content << i }
RSS::Parser.parse(content).items.each { |i| system "say \"#{i.title}\"" }
Displaying all 8 Code