Skip to content

Instantly share code, notes, and snippets.

View Puriney's full-sized avatar

Yun YAN Puriney

View GitHub Profile
@Puriney
Puriney / sum_of_number_string.pl
Created February 3, 2013 09:47
PERL: Sum of Number String
#!/usr/bin/perl -w
# string of number
# sum number larger than 0
# report start and end site
my $line = shift;
my @numbers = (split //,$line);
my $tag = 0;
my $sum = 0;
@Puriney
Puriney / DEG.test.R
Created March 9, 2013 17:19
R: DEG Poisson Fisher.test
set.seed(1026)
Cond1<-rpois(n=1000,lambda=5) #虽然用泊松分布模拟数据已经被吐槽了
Cond2<-rpois(n=1000,lambda=10)
df<-as.data.frame(cbind(cond1=Cond1,cond2=Cond2))
row.names(df)=paste("g",1:1000,sep="")
cond1Sum<-sum(df$cond1)
cond2Sum<-sum(df$cond2)
df$cond1Other<--df$cond1+cond1Sum
df$cond2Other<--df$cond2+cond2Sum
head (df)
@Puriney
Puriney / insertion_sort.pl
Created June 20, 2013 04:04
PERL: insertion_sort
# subroutine to implement insertion_sorting
#!/usr/bin/perl -w
sub insertion_sort {
my (@list) = @_;
foreach my $i (1 .. $#list){
my $j = $i;
my $tmp = $list[$i];
while ($j >0 && $tmp < $list[$j-1]){
$list[$j] = $list[$j-1];
$j --;
@Puriney
Puriney / MergeSortInversionTimes.pl
Created July 25, 2013 19:23 — forked from puriney2/MergeSortInversionTimes.pl
PERL: Merge Sort Inverstion Times
our $invTimes =0;
sub mergeSortInversions{
my @x =@_;
return @x if (@x < 2);
my $mid = int (@x/2);
my @a = mergeSortInversions(@x[0 .. $mid - 1]);
my @b = mergeSortInversions(@x[$mid .. $#x]);
for (my $i = 0; $i < @x; $i++) {
if (!@a){
@Puriney
Puriney / MergeSort.PL
Created July 25, 2013 19:23 — forked from puriney2/MergeSort.PL
PERL: Merge Sort
# http://rosettacode.org/wiki/Sorting_algorithms/Merge_sort#Perl
sub merge_sort {
my @x = @_;
return @x if @x < 2;
my $m = int @x / 2;
my @a = merge_sort(@x[0 .. $m - 1]);
my @b = merge_sort(@x[$m .. $#x]);
for (@x) {
$_ =
!@a ? shift @b :
@Puriney
Puriney / insertcode.sublime-snippet
Created July 25, 2013 19:23 — forked from puriney2/insertcode.sublime-snippet
ST: Snippet Insert Codes
<snippet>
<content><![CDATA[
{% highlight ${1:LanguageType} %}
${2:CodesHere}
{% endhighlight %}
$0]]></content>
<tabTrigger>mdcd</tabTrigger>
<scope>text.html.markdown.multimarkdown, text.html.markdown</scope>
</snippet>
@Puriney
Puriney / OS X termial theme
Created July 25, 2013 19:24 — forked from puriney2/OS X termial theme
BASH: Terminal Theme
# OS X termial theme
# tell ls to be colourful
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
# tell grep to highlight matches
export GREP_OPTIONS='--color=auto'
# alias
alias ls='ls -FGal'
# set custom bash prompt
#export PS1="\[\033[1;34m\]\!\[\033[0m\] \[\033[1;35m\]\u\[\033[0m\]:\[\033[1;35m\]\W\[\033[0m\]$ "
@Puriney
Puriney / QuickSort.PL
Created July 26, 2013 01:58
PERL: Quick Sort
#http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Perl
sub quick_sort {
my @a = @_;
return @a if @a < 2;
my $p = pop @a;
quick_sort(grep $_ < $p, @a), $p, quick_sort(grep $_ >= $p, @a);
}
my @array = (1,4,2,3,6,5,8,7);
@array = quick_sort @array;
print "@array\n";
@Puriney
Puriney / QuickSort.R
Created July 26, 2013 03:19
R: Quick Sort
qsort <- function(v) {
if ( length(v) > 1 )
{
pivot <- median(v) # median value as pivot value
c(qsort(v[v < pivot]), v[v == pivot], qsort(v[v > pivot]))
} else v
}
@Puriney
Puriney / SimpleSVM.R
Last active December 20, 2015 18:09 — forked from zjf/lazy_man_svm.R
R: SVM
set.seed(1026)
# dummy 2-D data: yi~xi(x1,x2)
x = rbind(cbind(rnorm(50, 1, 0.3), rnorm(50, 2, 0.3)), cbind(rnorm(50, 2, 0.3), rnorm(50, 1, 0.3)))
# [,1] [,2]
# [1,] 1.6565944 1.696906
# [2,] 0.9467358 1.458583
# [3,] 0.9444174 1.513886
# [4,] 0.2480391 2.273355
# [5,] 0.8328066 2.078371
# [6,] 0.9569322 2.174178