I have a problem with the value that checkboxes returns to me:
first of all i start with that 2 variables:
$blabla_severity_levels =
variable_get('blabla_severity_levels', array());
$blabla_severity_options = array();
then i make a for each for the watchdogs:
foreach (watchdog_severity_levels() as $severity_numbers => $severity) {
$blabla_severity_options[$severity_numbers] = check_plain(drupal_ucfirst($severity));
}
then i generate the form:
$blabla_form['blabla_severity_levels'] = array(
'#type' => 'checkboxes',
'#title' => t('Type of log messages'),
'#options' => $blabla_severity_options,
'#default_value' => array_values($blabla_severity_levels),
'#required' => TRUE,
);
return system_settings_form($blabla_form);
and in my function i call it like:
$severity_levels = variable_get('blabla_severity_levels', array());
now if i make a dpm($severity_levels)
it gets me out an array with
error (String, 5 characters ) error
warning (String, 7 characters ) warning
emergency (Integer) 0
alert (Integer) 0
critical (Integer) 0
notice (Integer) 0
info (Integer) 0
debug (Integer) 0
but i am really needing is the blabla_severity_options which is:
error (String, 5 characters ) 3
warning (String, 7 characters ) 4
emergency (Integer) 0
alert (Integer) 0
critical (Integer) 0
notice (Integer) 0
info (Integer) 0
debug (Integer) 0
I want to save the values...... any ideas plz?? i really need help
Related
I am looking for Observable.Window like operator with opening window selector
As example we can take a sequence of natural numbers.
I am wondering how to split this sequence into windows so every new window starts if number is greater than 4 or window size has reached 3
Input sequence is IObservable<int>
Output sequence is IObservable<IObservable<int>>
Sequence 1 2 5 3 1 1 2 3 1 5 0
will produce windows 1 2; 5 3 1; 1 2 3; 1; 5 0
Using C# this works:
var observable =
source
.Concat(Observable.Return(-1))
.Publish(sp =>
sp.Zip(sp.Skip(1), (x0, x1) => new { x0, x1 })
.Publish(zsp =>
zsp
.Window(zsp.Where(x => x.x1 >= 4))
.Select(xs => xs.Select(x => x.x0).Window(3))
.Merge()));
I get this result:
As per my comment on the question I am unsure whether the sequence 1, 2, 3, 5 should produce the windows 1 2 3 | 5 or 1 2 3 | | 5 (see the empty window which is what Enigmativity's answer produces). My answer does not produce the empty window:
public static IObservable<IObservable<T>> Window<T>(this IObservable<T> source, Func<T, bool> predicate, int maximumWindowSize)
{
return Observable.Create<IObservable<T>>(obs =>
{
var currentWindow = new Subject<T>();
obs.OnNext(currentWindow);
var count = 0;
return source.Subscribe(x =>
{
if (count == maximumWindowSize || predicate(x))
{
count = 0;
currentWindow.OnCompleted();
currentWindow = new Subject<T>();
obs.OnNext(currentWindow);
}
currentWindow.OnNext(x);
count++;
}, obs.OnError, () =>
{
obs.OnCompleted();
currentWindow.OnCompleted();
});
});
}
This can be used like so:
var windows = source.Window(x => x > 4, 3);
I am attempting to parse some M$ generated certs and finding that the phpseclib ASN1 decodeBER function is choking on some OID's. I would really like to understand this function better and its behavior in this case.
Here is an example cert for discussion:
-----BEGIN CERTIFICATE-----
MIIG1jCCBL6gAwIBAgITUAAAAA0qg8bE6DhrLAAAAAAADTANBgkqhkiG9w0BAQsF
ADAiMSAwHgYDVQQDExcuU2VjdXJlIEVudGVycHJpc2UgQ0EgMTAeFw0xNTAyMjMx
NTE1MDdaFw0xNjAyMjMxNTE1MDdaMD8xFjAUBgoJkiaJk/IsZAEZFgZzZWN1cmUx
DjAMBgNVBAMTBVVzZXJzMRUwEwYDVQQDEwxtZXRhY2xhc3NpbmcwggEiMA0GCSqG
SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDMdG1CzR/gTalbLN9J+2cvMGeD7wsR7S78
HU5hdwE+kECROjRAcjFBOR57ezSDrkmhkTzo28tj0oAHjOh8N9vuXtASfZSCXugx
H+ImJ+E7PA4aXBp+0H2hohW9sXNNCFiVNmJLX66O4bxIeKtVRq/+eSNijV4OOEkC
zMyTHAUbOFP0t6KoJtM1syNoQ1+fKdfcjz5XtiEzSVcp2zf0MwNFSeZSgGQ0jh8A
Kd6YVKA8ZnrqOWZxKETT+bBNTjIT0ggjQfzcE4zW2RzrN7zWabUowoU92+DAp4s3
sAEywX9ISSge62DEzTnZZSf9bpoScAfT8raRFA3BkoJ/s4c4CgfPAgMBAAGjggLm
MIIC4jAdBgNVHQ4EFgQULlIyJL9+ZwAI/SkVd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O9aPjvPLzjd5bY322L8lxh5wy5my
DKmip+irzjdVdxzQfoyy+ceODmCbX9L6MfEDn0RBzdwjLe1/eOxE1na0sZztrVCc
yt5nI91NNGZJUcVqVQsIA/25FWlkvo/FTfuqTuXdQiEVM5MCKJI915anmTdugy+G
0CmBJALIxtyz5P7sZhaHZFNdpKnx82QsauErqjP9H0RXc6VXX5qt+tEDvYfSlFcc
0lv3aQnV/eIdfm7APJkQ3lmNWWQwdkVf7adXJ7KAAPHSt1yvSbVxThJR/jmIkyeQ
XW/TOP5m7JI/GrmvdlzI1AgwJ+zO8fOmCDuif99pDb1CvkzQ65RZ8p5J1ZV6hzlb
VvOhn4LDnT1jnTcEqigmx1gxM/5ifvMorXn/ItMjKPlb72vHpeF7OeKE8GHsvZAm
osHcKyJXbTIcXchmpZX1efbmCMJBqHgJ/qBTBMl9BX0+YqbTZyabRJSs9ezbTRn0
oRYl21Q8EnvS71CemxEUkSsKJmfJKkQNCsOjc8AbX/V/X9R7LJkH3UEx6K2zQQKK
k6m17mi63YW/+iPCGOWZ2qXmY5HPEyyF2L4L4IDryFJ+8xLyw3pH9/yp5aHZDtp6
833K6qyjgHJT+fUzSEYpiwF5rSBJIGClOCY=
-----END CERTIFICATE-----
For simple testing purposes this is my driver:
$X509 = new File_X509();
$BER = $X509->_extractBER($BER);
$ASN1 = new File_ASN1();
$ASN1->loadOIDs($X509->oids);
$DECODED = $ASN1->decodeBER( $BER );
Utility::dumper($DECODED);
I think we are running into trouble ~line 423:
case FILE_ASN1_TYPE_OCTET_STRING:
if (!$constructed) {
$current['content'] = $content;
} else {
$current['content'] = '';
$length = 0;
while (substr($content, 0, 2) != "\0\0") {
$temp = $this->_decode_ber($content, $length + $start);
$this->_string_shift($content, $temp['length']);
// all subtags should be octet strings
//if ($temp['type'] != FILE_ASN1_TYPE_OCTET_STRING) {
// return false;
//}
$current['content'].= $temp['content'];
$length+= $temp['length'];
}
if (substr($content, 0, 2) == "\0\0") {
$length+= 2; // +2 for the EOC
}
}
break;
Specifically in dumping the output of array element 7 (subjectAltName)
[7] => Array
(
[start] => 1104
[headerlength] => 2
[type] => 16
[content] => Array
(
[0] => Array
(
[start] => 1106
[headerlength] => 2
[type] => 6
[content] => 2.5.29.17
[length] => 5
)
[1] => Array
(
[start] => 1111
[headerlength] => 2
[type] => 4
[content] => 0% #^F+^F^A^D^A^Â7^T^B^C ^U^L^Smetaclassing#secure
[length] => 41
)
)
[length] => 48
)
It appears that the content should be parsed into an array instead of a string of binary junk. I believe it should parse into something more like this:
SEQUENCE(2 elem)
OBJECT IDENTIFIER2.5.29.17
OCTET STRING(1 elem)
SEQUENCE(1 elem)
Offset: 1113
Length: 2+37
(constructed)
Value:
(1 elem)
[0](2 elem)
OBJECT IDENTIFIER1.3.6.1.4.1.311.20.2.3
[0](1 elem)
UTF8String metaclassing#secure
I believe this is a "constructed" field, however up at line ~298 the bitwise operation happening is a little beyond my understanding:
$constructed = ($type >> 5) & 1;
I have written a corner-case matching hex values to force $constructed to 1 for this specific array element but didnt see much of an improvement in parsing. Wondering what the next best step is to remedy this? I really appreciate your help and thoughts. Thanks!
you should attempt to recurse OCTET_STRING contents and attempt to decode the nested record to see if it decodes as valid ASN.1. All certificate extension values are placed as a nested to OCTET_STRING structure:
From what I know, the following primitive tags are used in primitive form only: BOOLEAN, INTEGER, NULL, OBJECT_IDENTIFIER, REAL, ENUMERATED and RELATIVE_OID. The rest primitive tags may have embedded content. Although, this list is not definitive, OCTET_STRING definitely may be a container even if its tag is encoded in a primitive form. This applies to BIT_STRING as well.
Yes indeed, the code should recur. Here are my findings thus far:
$class = ($type >> 6) & 3;
The issue does appear to be the bitwise operation being used, it is not correctly identifying class (is returning 0 for application when it should be 2 for context specific and 0 for constructed which should be 1.
To test I inserted this code below (really hackish, but im an ASN.1n00b:
// Manual testing for incorrect class/constructed detection!
if ( !$constructed && $class == 0 && isset($content[0]) && isset($content[1]) )
{
//print "\nSTART: $start\tTYPE IS: {$type}\t CLASS IS: {$class}\tCONTENT IS {$content}\n";
if ( ($content[0] == "0" && $content[1] == "%" ) ||
($content[0] == hex2bin("30") && $content[1] == hex2bin("81") ) ||
($content[0] == hex2bin("82") && $content[1] == hex2bin("01") ) ||
($content[0] == hex2bin("30") && $content[1] == hex2bin("20") ) ||
($content[0] == hex2bin("1e") && $content[1] == hex2bin("08") ) ||
($content[0] == hex2bin("00") && $content[1] == hex2bin("55") ) ||
($content[0] == hex2bin("04") && $content[1] == hex2bin("14") ) ||
($content[0] == hex2bin("30") && $content[1] == hex2bin("16") ) ||
($content[0] == hex2bin("00") && $content[1] == hex2bin("30") ) )
{
$class = 2; $constructed = 1; //print "SET CLASS AND CONSTRUCTED!\n";
}else{
//print "C0: {$content[0]} = (0x" . bin2hex($content[0]) . ") C1: {$content[1]} = (0x" . bin2hex($content[1]) . ") did not match!\n";
}
}
And indeed, manually matching the bytes not correctly detected does resolve my issue:
[7] => Array
(
[start] => 1104
[headerlength] => 2
[type] => 16
[content] => Array
(
[0] => Array
(
[start] => 1106
[headerlength] => 2
[type] => 6
[content] => 2.5.29.17
[length] => 5
)
[1] => Array
(
[type] => 2
[constant] => 4
[content] => Array
(
[0] => Array
(
[start] => 1113
[headerlength] => 2
[type] => 16
[content] => Array
(
[0] => Array
(
[type] => 2
[constant] => 0
[content] => Array
(
[0] => Array
(
[start] => 1117
[headerlength] => 2
[type] => 6
[content] => 1.3.6.1.4.1.311.20.2.3
[length] => 12
)
)
[length] => 14
[start] => 1115
[headerlength] => 2
)
[1] => Array
(
[type] => 2
[constant] => 0
[content] => Array
(
[0] => Array
(
[start] => 1131
[headerlength] => 2
[type] => 12
[content] => metaclassing#secure
[length] => 21
)
)
[length] => 23
[start] => 1129
[headerlength] => 2
)
)
[length] => 39
)
)
[length] => 41
[start] => 1111
[headerlength] => 2
)
)
[length] => 48
)
At this point I think I need to wait for the library developers to review the ASN.1 parsing function/library and review why these certs make it so incredibly unhappy. Patching this is somewhat beyond my capabilities at the moment.
I have this search query in php:
[$near] => Array(
[0] => -73.5539925
[1] => 45.5086699
)
[$maxDistance] => 0.269978401728
0.269978401728 was calculated this way: 30/111.12
problem is that it doesn't find point with these values: -73.8260706 45.4293058
it finds it only if distance is increased to 32.
If I check gmap walking distance between these points is 26.6 which is longer than direct line. Then even with 25km it should probably work, but now it doesnt work with 30.
Do I miss something?
Thanks
I changed query to use within instead of near and now it works fine
$radiusOfEarth = 6378.1;//radius in km
$calculated_distance = (float) $distance / $radiusOfEarth;
$search = array(
'loc' => array('$within' =>
array('$centerSphere' =>
array(
array(floatval($lng), floatval($lat)), $calculated_distance
)
)
)
);
or
[loc] => Array
(
[$within] => Array
(
[$centerSphere] => Array
(
[0] => Array
(
[0] => -73.5539925
[1] => 45.5086699
)
[1] => 0.00501716812217
)
)
)
I've spent the whole day trying to figure out how to JOIN / group my query below, can someone help me or guide me to complete the desired output? -i enclosed some of the foreign key values for easy reference)
Below is my Table Grade
rowID testID studentID Grade
1 1 1(class2011) 50
2 1 1(class2011) 90
3 2 1(class2011) 100
4 2 2(class2012) 85
--Student table
StudentID Classyear
1 2(class2011)
2 3(class2012)
3 1(class2010)
--Classyear Table
ClassYearID Desc
1 2010
2 2011
3 2012
My query below (to display the testID, failed(passing rate=80), passed, taken, Rate)
var h = list.GroupBy(a => a.testID)
.Select(a => {
int _failed = a.Count(g => g.Grade < 80);
int _passed = a.Count(g => g.Grade >= 80);
int _rate = (int)(_passed / (double)a.Count() * 100.0);
return new {
testID = a.Key,
failed = _failed,
passed = _passed,
taken = a.Count(),
rate = _rate,
};
});
The result1
testID failed passed taken Rate
1 1 1 2 50%
2 0 2 2 100%
Now here's my BIG problem: the students in my table grade above DOES NOT belong in the
same classyear. I need to group this by testID and classyear.
See below for the desired output:
testID ClassyearID failed passed taken Rate
1 1(2010) 0 0 0 0
1 2(2011) 1 1 2 50%
1 3(2012) 0 0 0 0
2 1(2010) 0 0 0 0
2 2(2011) 0 1 1 100%
2 3(2012) 0 1 1 100%
You can immediately see the difference from result 1. stats for Test2 is divided for class 2011 and class 2012.
Hope I did explain clear enough my intentions. Maybe I will post later my crappy code trying to get the desired output. Thanks
Can't you just do this?:
var h = list.GroupBy(a =>new {a.testID,a.classyear})
.Select(a => {
int _failed = a.Count(g => g.Grade < 80);
int _passed = a.Count(g => g.Grade >= 80);
int _rate = (int)(_passed / (double)a.Count() * 100.0);
return new {
testID = a.Key.testID,
classyear=a.Key.classyear,
failed = _failed,
passed = _passed,
taken = a.Count(),
rate = _rate,
};
});
I set x_label_skip to skip labels, but it still tries to display the very last label and it is overwriting the other label, and looks messy. It shouldn't be writing the last label. It should be skipping the last label. I set the number of labels to skip as a function of how many data points there are.
This is what it looks like:
Code:
my $graph = GD::Graph::lines->new(400, 500);
$graph->set(
r_margin => 2,
x_label => 'Date',
y_label => 'Price',
title => "$symbol1, $symbol2",
dclrs => [ qw(lred lblue lgreen lyellow lpurple cyan lorange) ],
transparent => 0,
x_labels_vertical => 1,
x_label_skip => int ((#tmpDate * 8)/(400-50) + 1), # a function of # of data points, each label 8px. More labels, more skip.
) or die $graph->error;
Ok I found it. Just use modulo to divide the # of entries by # of labels to skip, and use that as the offset. It seems GD::Graph will always want to print the last label, so can't control that, but you can control the 1st label to print. Seems backwards to me but whatever.
my $graph = GD::Graph::lines->new(400, 500);
my $skip = int ((#tmpDate * 8)/(400-50) + 1); # a function of # of data points, each label 8px. More labels, more skip.
$graph->set(
r_margin => 2,
x_label => 'Date',
y_label => 'Price',
title => "$symbol1, $symbol2",
dclrs => [ qw(lred lblue lgreen lyellow lpurple cyan lorange) ],
transparent => 0,
x_labels_vertical => 1,
x_label_skip => $skip,
x_tick_offset => #tmpDate % $skip, # ensure last label doesn't overwrite second-to-last label
) or die $graph->error;
x_last_label_skip => 1 works exactly as you need it, just skipping the last label. Probably it wasn't implemented in 2012, but now it is.