Skip to content

Instantly share code, notes, and snippets.

View jyotty's full-sized avatar

Joshua Yotty jyotty

View GitHub Profile
@jyotty
jyotty / gist:2794985
Created May 26, 2012 19:07
perl6: not quite ready
$ time perl -MList::Util=reduce -le 'print reduce { $a + $b } (1..1000000)'
500000500000
perl -MList::Util=reduce -le 'print reduce { $a + $b } (1..1000000)' 0.22s user 0.05s system 98% cpu 0.275 total
$ time ruby -e 'puts (1..1000000).inject(0) {|x,i| x+i}'
500000500000
ruby -e 'puts (1..1000000).inject(0) {|x,i| x+i}' 0.14s user 0.04s system 98% cpu 0.187 total
$ time perl6 -e 'print [+] 1..1000000' # rakudo star 201201
500000500000perl6 -e 'print [+] 1..1000000' 478.78s user 5.98s system 99% cpu 8:08.09 total
$ time perl6 -e 'print [+] 1..1000000' # rakudo star 201205
500000500000perl6 -e 'print [+] 1..1000000' 25.94s user 0.67s system 99% cpu 26.626 total
@jyotty
jyotty / about_control_statements.rb
Created February 12, 2012 02:16
Doing ruby koans again as a refresher, getting a little impatient
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
class AboutControlStatements < EdgeCase::Koan
# …
def test_while_statement
i = 1
result = 1
while i <= 10
result = result * i
i += 1
@jyotty
jyotty / pointless.c
Created January 6, 2012 07:13
print 1 .. 1000 without loops or conditionals
#include <stdio.h>
int main(void)
{
fall(1);
}
int fall(int e)
{
int a = 1/(1001-e);
@jyotty
jyotty / gist:1521579
Created December 26, 2011 16:41
This is why ‘use warnings' is important and ‘use diagnostics’ is helpful
$ perl -E'open my $fh, "test"; print {$fh} "butts"'
$ perl -Mwarnings -E'open my $fh, "test"; print {$fh} "butts"'
Filehandle $fh opened only for input at -e line 1.
$ perl -Mwarnings -Mdiagnostics -E'open my $fh, "test"; print {$fh} "butts"'
Filehandle $fh opened only for input at -e line 1 (#1)
(W io) You tried to write on a read-only filehandle. If you intended
it to be a read-write filehandle, you needed to open it with "+<" or
"+>" or "+>>" instead of with "<" or nothing. If you intended only to
write the file, use ">" or ">>". See "open" in perlfunc.
@jyotty
jyotty / gist:1470660
Created December 13, 2011 04:53
YES IT LOOKS REASONABLE
The following changes, which occurred between FreeBSD 7.3-RELEASE and
FreeBSD 7.4-RELEASE have been merged into /etc/passwd:
--- current version
+++ new version
@@ -1,6 +1,6 @@
-# $FreeBSD: src/etc/master.passwd,v 1.40.24.1 2010/02/10 00:26:20 kensmith Exp $
+# $FreeBSD: src/etc/master.passwd,v 1.40.26.1 2010/12/21 17:10:29 kensmith Exp $
#
root:*:0:0:Charlie &:/root:/bin/tcsh
toor:*:0:0:Bourne-again Superuser:/root:
@jyotty
jyotty / what.pl
Created November 22, 2011 18:17
I can't speak for what I was thinking at the time.
if (!grep { $action eq $_ } @Controller::actions) {
unshift(@parts, $action, 404);
$action = 'error';
}
# …
my $sub;
{
no strict 'refs';
@jyotty
jyotty / gist:1386329
Created November 22, 2011 17:40
libkitchensink{a}
# aptitude install collectd
The following NEW packages will be installed:
collectd collectd-core{a} dbus-x11{a} gconf2{a} libasound2{a} libcanberra-gtk-module{a}
libcanberra-gtk0{a} libcanberra0{a} libcap-ng0{a} libesmtp5{a} libhal1{a} libmemcached5{a}
libnl1{a} libnotify1{a} libogg0{a} libopenipmi0{a} liboping0{a} libprotobuf-c0{a}
libpython2.6{a} libstartup-notification0{a} libtdb1{a} libtokyotyrant3{a} libupsclient1{a}
libvirt0{a} libvorbis0a{a} libvorbisfile3{a} libwnck-common{a} libwnck22{a} libxcb-aux0{a}
libxcb-event1{a} libxenstore3.0{a} libxres1{a} libyajl1{a} notification-daemon{a} rrdtool{a}
@jyotty
jyotty / xrcexample.pl
Created November 9, 2011 20:26
let me out of this issue three
# example perl code shipped by a company who seems to have written their backend in perl:
for(my $i = 0; $summaries->[$i]; $i++) {
my $summary = $summaries->[$i];
# …
my $offerIds =$summary->{"offerIDs"};
for(my $j = 0; $offerIds->[$j]; $j++) {
print "Offer ID: " . $offerIds->[$j] . "\n";
}
}
@jyotty
jyotty / gist:1252008
Created September 29, 2011 21:37
erryday I'm segfaulting
$ perlbrew exec perl -e version::new
perl-5.10.1
==========
sh: line 1: 21919 Segmentation fault perl \-e version\:\:new
perl-5.12.2
==========
sh: line 1: 21922 Segmentation fault perl \-e version\:\:new
@jyotty
jyotty / gist:1148031
Created August 15, 2011 22:21
perfectly readable
perl -E 'say for sort { length $b <=> length $a } map { (split /\t/)[-1] } split /\n/, do "unicore/Name.pl"'