This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Fixnum | |
| def degrees_to_compass | |
| %w( N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW )[((self+11.25).modulo(360)/22.5).floor] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Use .netrc for credentials. See netrc(5) manpage for format. | |
| echo status=“`fortune -n 138 -s`” | curl -n -d @- https://api.twitter.com/1/statuses/update.json >& /dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Tweet weather forecast | |
| # - gets forecast from Yahoo weather API | |
| # - reads HTTPClient config from ~/.httpclient.yml and Twitter OAuth credentials from ~/.oauth.yml | |
| require 'yaml' | |
| require 'xmlsimple' | |
| require 'httpclient' | |
| require 'oauthclient' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sub url2thumb { | |
| my $url = shift; | |
| return "http://flic.kr/p/img/$1_t.jpg" if $url =~ qr{^http://flic\.kr/p/([a-zA-Z0-9]*)}; | |
| return "http://yfrog.com/$1.th.jpg" if $url =~ qr{^http://yfrog\.(?:com|ru|com\.tr|it|fr|co\.il|co\.uk|com\.pl|pl|eu)/([0-9a-zA-Z]*[jpbtgfzx])}; | |
| return "http://twitpic.com/show/thumb/$1" if $url =~ qr{^http://twitpic\.com/([a-zA-Z0-9])*}; | |
| return "http://img.ly/show/thumb/$1" if $url =~ qr{^http://img\.ly/([a-zA-Z0-9]*)}; | |
| return "http://pic.im/website/thumbnail/$1" if $url =~ qr{^http://pic\.im/([a-zA-Z0-9]*)}; | |
| return "http://twitgoo.com/$1/thumb" if $url =~ qr{^http://twitgoo\.com/([a-zA-Z0-9]*)}; | |
| return "http://ctr.lv/rest/small/thumb/$1" if $url =~ qr{^http://ctr\.lv/([a-zA-Z0-9]*)}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use Lingua::Romana::Perligata; | |
| ute UserAgent intra LWP. | |
| ute Headers intra HTTP. | |
| adnota >>> Change the URL below if needed <<<. | |
| meo statio da dictum sic https://graph.facebook.com/me cis. | |
| adnota >>> Replace <oauth2-token> with your OAuth 2.0 token <<<. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sudo /Applications/Install\ OS\ X\ Mavericks.app/Contents/Resources/createinstallmedia --volume /Volumes/Untitled --applicationpath /Applications/Install\ OS\ X\ Mavericks.app --nointeraction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Usage: my $name = guess_name_from_email( $email ); | |
| sub guess_name_from_email { | |
| return join q( ), map { ucfirst lc } ( sub { ( shift, pop ) } )->( split /\./, ( split /@/, shift )[0] ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Usage: "[email protected]".guess_name_from_email | |
| class String | |
| def guess_name_from_email | |
| self.split('@')[0].split('.').instance_exec { [ shift, pop ] }.compact.map { |n| n.capitalize }.join(' ') | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension BinaryInteger where Self.Stride: SignedInteger { | |
| /// Calculates the factorial of this value | |
| /// - Precondition: the value must be positive or zero | |
| func factorial() -> Self { | |
| precondition(self >= 0, "Can't calculate the factorial of a negative number") | |
| return self < 2 ? 1 : (2...self).reduce(1, *) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let fibonacci = sequence(state: (0,1)) { (state: inout (Int,Int)) -> Int in | |
| state = (state.1, state.0 + state.1) | |
| return state.1 | |
| } |
OlderNewer