Skip to content

Instantly share code, notes, and snippets.

@Cside
Cside / mock-titanium-methods.js
Created March 29, 2012 05:22
mock of titanium's methods
(function () {
if (typeof Ti !== 'undefined') return;
var global = new Function('return this;')();
var Titanium = function () {};
Titanium['API'] = function () {};
Titanium['Accelerometer'] = function () {};
Titanium['Analytics'] = function () {};
Titanium['Android'] = function () {};
@Cside
Cside / get_git_branch_name.zsh
Created March 23, 2012 04:01
get_git_branch_name.zsh
#!zsh
function git_info() {
local info
if test -z $(git rev-parse --git-dir 2> /dev/null); then
info=''
else
info="${$(git symbolic-ref HEAD 2> /dev/null)#refs/heads/}"
fi
echo -n "$info"
}
@Cside
Cside / perl.snip
Created March 21, 2012 10:45
Perl code snippets
snippet u
#!/usr/bin/env perl
use 5.10.0;
use strict;
use warnings;
snippet d
use Data::Dump qw(dump);
warn dump
@Cside
Cside / object_keys_values.js
Created March 20, 2012 11:49
Object.keys(), Object.values()
Object.prototype.keys = function (i) {
var keys = Object.keys(this);
return (i >= 0) ? keys[i] : keys;
};
Object.prototype.values = function (i) {
var self = this;
var values = Object.keys(this).map(function(key){
return self[key];
});
@Cside
Cside / Parent.pm
Created March 13, 2012 04:56
Inheritance test on Perl
package Parent;
use strict;
use warnings;
sub new { bless {}, $_[0] }
1;
@Cside
Cside / retrying_http_get.pl
Created February 16, 2012 12:13
retry http get
use LWP::UserAgent;
use Sub::Retry qw(retry);
my $TryTimes = 3;
my $Interval = 1;
my $UserAgent = LWP::UserAgent->new;
sub _ua { $UserAgent->clone }
sub get {
@Cside
Cside / dump_uri.pl
Created February 16, 2012 11:23
dump uri
use URI;
use Data::Dumper;
sub dump_uri {
my $uri = ref($_[0]) eq 'URI::http' ? $_[0] : URI->new($_[0]);
my ($base, $param_string) = split /\?/, $uri;
my $result = $base;
if ($param_string) {
$result .= "\n";
local $Data::Dumper::Indent = 1;
local $Data::Dumper::Terse = 1;
@Cside
Cside / gist:1759654
Created February 7, 2012 13:23
hook_before_import.pl
BEGIN {
no warnings 'redefine';
no strict 'refs'
my $orig = \&{__PACKAGE__ . '::import'};
*{__PACKAGE__ . '::import'} = sub {
...
$orig->(@_);
};
};
--- vimparse.pl.old 2011-12-25 22:19:36.000000000 +0900
+++ vimparse.pl 2011-12-26 00:01:48.000000000 +0900
@@ -63,6 +63,9 @@
use strict;
use Getopt::Std;
+use Cwd qw(getcwd);
+use Path::Class qw(file);
+use Project::Libs;
@Cside
Cside / send_to_gmail.pl
Created December 19, 2011 15:50
send email to gmail-adress with attachment.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Path::Class qw/file/;
use Encode;
use Email::Sender::Simple qw/try_to_sendmail/;
use Email::MIME;
use Email::MIME::Creator;
use Email::Sender::Transport::SMTP::TLS;