- www.gideondsouza.com
This file contains 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
package Dancer2::Plugin::Auth::Github; | |
use strict; | |
use warnings FATAL => 'all'; | |
use Carp 'croak'; | |
use Dancer2; | |
use Dancer2::Plugin; | |
use Digest::SHA qw(sha256_hex); |
This file contains 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
package YourDancerApplication; | |
use Dancer2; | |
use lib "../dancer2-plugin-auth-github/lib"; | |
use Dancer2::Plugin::Auth::Github; | |
set 'session' => 'YAML'; | |
auth_github_init(); | |
This file contains 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
cpanm (App::cpanminus) 1.6942 on perl 5.012004 built for darwin-thread-multi-2level | |
Work directory is /Users/gideon/.cpanm/work/1379605518.67859 | |
You have make /usr/bin/make | |
You have LWP 6.05 | |
You have /usr/bin/tar: bsdtar 2.8.3 - libarchive 2.8.3 | |
You have /usr/bin/unzip | |
Searching Tkx on cpanmetadb ... | |
--> Working on Tkx | |
Fetching http://www.cpan.org/authors/id/G/GA/GAAS/Tkx-1.09.tar.gz | |
-> OK |
This file contains 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
package YourDancerApplication; | |
use Dancer ':syntax'; | |
use Dancer::Plugin::Auth::Github; | |
#You must use a session backend. | |
#You should be able to use any backend support by dancer. | |
set 'session' => 'Simple'; | |
#make sure you call this first. |
This file contains 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
package MyWebService; | |
use Dancer; | |
use Dancer::Plugin::REST; | |
#this line kicks in the plugin. So now whatever you return will be formatted and send back | |
prepare_serializer_for_format; | |
#this sets up a route that takes an id a dot and an extension | |
get '/user/:id.:format' => sub { | |
User->find(params->{id});#return some reference to a hash or array or what have you | |
}; |
This file contains 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 Dancer; | |
get '/' => sub { | |
"Hello World!" | |
}; | |
dance; |
This file contains 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 LWP::UserAgent; | |
use LWP::Protocol::PSGI; | |
# can be Mojolicious, Catalyst ... any PSGI application | |
my $psgi_app = do { | |
use Dancer;#ATTENTION: changing this to Dancer2 makes this sample NOT WORK. | |
setting apphandler => 'PSGI'; | |
get '/search' => sub { | |
return 'googling ' . params->{q}; | |
}; |
This file contains 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
>>> | |
>>> L = [1,2,3,4,5] #define a list 1 to 5 | |
>>> [(x,y) for x in L for y in L] # we have two fors running over the list | |
#this gives all the 25 non-unique combinations | |
[(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), | |
(3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), | |
(5, 1), (5, 2), (5, 3), (5, 4), (5, 5)] | |
#need unque combinations. No problem! Add an if in the end. | |
>>> [(x,y) for x in L for y in L if x!=y] | |
[(1, 2), (1, 3), (1, 4), (1, 5), (2, 1), (2, 3), (2, 4), (2, 5), (3, 1), (3, 2), |
This file contains 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
>>> #The tuple is a common CS structure. | |
>>> T = (1,2,3) #think of it as a record | |
>>> type(T) | |
<class 'tuple'> | |
#you're not limited to numbers, you can store anything in a tuple, list, set etc. | |
>>> Friends = ("Bill", "Bob", "Will") | |
>>> Friends[0] #access it's first element. | |
'Bill' | |
>>> T[2] | |
3 |
This file contains 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
>>> | |
>>> S = {1,3} #a new set with two elements | |
>>> type(S) #what is the type of S? | |
<class 'set'> | |
>>> S1 = {3,4,5} #initialize two sets S1 and S2 | |
>>> S2 = {3,6,7} | |
>>> S1 | S2 #this will give you a union of the two. | |
{3, 4, 5, 6, 7} | |
>>> #you can also use & for intersection, and ^ for xor |