Skip to content

Instantly share code, notes, and snippets.

View pjlsergeant's full-sized avatar
🙇‍♂️
I don't really have time for this anymore

Peter Sergeant pjlsergeant

🙇‍♂️
I don't really have time for this anymore
  • Bangkok, Thailand
View GitHub Profile
package FixEncodings;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(explain attempt_decode);
# This should be in terms of longest first
#!/opt/xt/xt-perl/bin/perl
use strict;
use warnings;
use File::Spec;
use Git::Wrapper;
use Cwd 'realpath';
use Term::ANSIColor;
use Term::ReadKey;
function epochToAgo ( epoch ) {
var rightNowObj = new Date();
var rightNowEpoch = Math.floor(rightNowObj.getTime() / 1000);
var diff = rightNowEpoch - epoch;
var human;
if ( diff < 3600 ) {
human = Math.floor( diff / 60 ) + ' minutes ago';
} else if ( diff < 86400 ) {
sub permutation {
my ( $count, $columns, $permutations ) = @_;
my $total_permutations = @$permutations ** $columns;
return if $count >= $total_permutations;
my $num = $count;
my $base = @$permutations;
sub permutation {
my ( $desired_permutation, $column_count, $permutation_set ) = @_;
my $permutation_set_count = @$permutation_set;
# The total number of permutations
my $total_permutations = $permutation_set_count ** $column_count;
# Return if we're being asked for a permutation outside the total number
# possible
return if $desired_permutation >= $total_permutations;
@pjlsergeant
pjlsergeant / explain.pl
Last active September 24, 2015 15:58
explain()
# Given a string, print out the codepoints that it currently compromises of. If
# you pass it a bytestring, you will get the bytes. If you pass it a character
# string, you will get the characters. This can be helpful when you're not sure
# if your terminal is playing around with the output.
sub explain {
# We will build up the output in $explain
my $explain;
# Split the first argument in to characters
for my $char ( split(//, shift() ) ) {
@pjlsergeant
pjlsergeant / gist:981539
Created May 19, 2011 19:33
Healthy carbonara recipe
Name : Healthy Carbonara
Serves: 4 x 371 calorie portions (so two meals for me)
Stats:
Calories : 371 kcal (calc: 373)
% Fat : 28% - 106 kcal - 12g
% Protein: 27% - 101 kcal - 25g
% Carbs : 45% - 167 kcal - 42g
[
abc =>
[ '<!--', "I am a comment" ], # This is a magic tag
[ '<![CDATA[', "I am some CDATA" ], # This is also a magic tag
"\nHere is &, an ampersand, which will be quoted automatically",
\"\nHere is &ampersand;, an ampersand - string refs are 'raw'",
[ 'bar', { 'foo' => "The first hashref is the attributes" }, "some stuff" ],
[ 'single_no_attr' ],
diff -rubw /tmp/Catalyst-Plugin-Authentication-0.10017//lib/Catalyst/Authentication/Credential/Password.pm ./lib/Catalyst/Authentication/Credential/Password.pm
--- /tmp/Catalyst-Plugin-Authentication-0.10017//lib/Catalyst/Authentication/Credential/Password.pm 2011-01-24 23:29:57.000000000 +0000
+++ ./lib/Catalyst/Authentication/Credential/Password.pm 2011-06-27 09:01:01.000000000 +0100
@@ -25,7 +25,7 @@
$self->_config->{'password_hash_type'} ||= 'SHA-1';
my $passwordtype = $self->_config->{'password_type'};
- if (!grep /$passwordtype/, ('none', 'clear', 'hashed', 'salted_hash', 'crypted', 'self_check')) {
+ if (!grep /$passwordtype/, ('none', 'clear', 'hashed', 'salted_hash', 'crypted', 'self_check', 'custom')) {
Catalyst::Exception->throw(__PACKAGE__ . " used with unsupported password type: " . $self->_config->{'password_type'});
@pjlsergeant
pjlsergeant / upgrading passwords.js
Created June 28, 2011 14:26
Upgrading passwords in place
// How to upgrade your users passwords in the DB without their intervention
//
// SHA-1 isn't strong enough to hash passwords with, but lots of people have a
// whole bunch of SHA-1'd passwords because they thought it was. You could use
// bcrypt or scrypt, but maybe in two years' time someone will tell you that's
// also not strong enough, and you'll want to upgrade.
//
// This sample demonstrates how you can remove weak password hashes from your
// user database, without needing the user to enter their password.
//