Related
How to set the scss dynamic class name using margin values.
This is what I tried
$spaceamounts: (1, 3, 5, 8, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 110, 120, 130, 140,150,160,170,180,);
$sides: (top, bottom, left, right);
#each $space in $spaceamounts {
#each $side in $sides {
.m#{str-slice($side, 0, 1)}-#{$space} {
margin-#{$side}: #{$space}px !important;
}
.p#{str-slice($side, 0, 1)}-#{$space} {
padding-#{$side}: #{$space}px !important;
}
}
}
So I can use margin/padding class name like pt-1, mt-10
But I want to set the $spaceamounts value as 1~999.
Anyone know how to fix the code?
If you want to create a class for every values between 1 and 999, you can get rid of $spaceamounts and use a #for loop:
$sides: (top, bottom, left, right);
#for $i from 1 through 999 {
#each $side in $sides {
.m#{str-slice($side, 0, 1)}-#{$i} {
margin-#{$side}: #{$i}px !important;
}
.p#{str-slice($side, 0, 1)}-#{$i} {
padding-#{$side}: #{$i}px !important;
}
}
}
For what it's worth, I think that it's not something you should do as it will generate a massive amount of code.
How would one re-write the following in proper Java 8 functional style using filter, collector, etc:
private BigInteger calculateProduct(char[] letters) {
int OFFSET = 65;
BigInteger[] bigPrimes = Arrays.stream(
new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113 })
.mapToObj(BigInteger::valueOf)
.toArray(BigInteger[]::new);
BigInteger result = BigInteger.ONE;
for (char c : letters) {
//System.out.println(c+"="+(int)c);
if (c < OFFSET) {
return new BigInteger("-1");
}
int pos = c - OFFSET;
result = result.multiply(bigPrimes[pos]);
}
return result;
}
#Test public void test() {
assertThat(calculateProduct(capitalize("carthorse"))).isEqualTo(calculateProduct(capitalize("orchestra")));
}
private char[] capitalize(String word) {
return word.toUpperCase().toCharArray();
}
You may do it like this:
static final BigInteger[] PRIMES
= IntStream.of(
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113)
.mapToObj(BigInteger::valueOf)
.toArray(BigInteger[]::new);
private BigInteger calculateProduct(char[] letters) {
final int OFFSET = 65;
final CharBuffer cb = CharBuffer.wrap(letters);
if(cb.chars().anyMatch(c -> c<OFFSET))
return BigInteger.ONE.negate();
return cb.chars()
.mapToObj(c -> PRIMES[c-OFFSET])
.reduce(BigInteger.ONE, BigInteger::multiply);
}
Note that moving the creation of the PRIMES array out of the method, to avoid generating it again for each invocation, is an improvement that works independently of whether you use loops or “functional style” operations.
Also, your code doesn’t handle characters being too large, so you might improve the method to
private BigInteger calculateProduct(char[] letters) {
final int OFFSET = 65;
final CharBuffer cb = CharBuffer.wrap(letters);
if(cb.chars().mapToObj(c -> c-OFFSET).anyMatch(c -> c<0||c>PRIMES.length))
return BigInteger.ONE.negate();
return cb.chars()
.mapToObj(c -> PRIMES[c-OFFSET])
.reduce(BigInteger.ONE, BigInteger::multiply);
}
I can't tell why you want that, but may be this (which creates many more objects and is more verbose):
private static BigInteger calculateProduct(char[] letters) {
int OFFSET = 65;
BigInteger[] bigPrimes = Arrays.stream(
new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113 })
.mapToObj(BigInteger::valueOf)
.toArray(BigInteger[]::new);
Optional<Character> one = IntStream.range(0, letters.length)
.mapToObj(x -> letters[x])
.filter(x -> x < OFFSET)
.findAny();
if (one.isPresent()) {
return new BigInteger("-1");
} else {
return IntStream.range(0, letters.length)
.mapToObj(x -> letters[x])
.parallel()
.reduce(
BigInteger.ONE,
(x, y) -> {
int pos = y - OFFSET;
return x.multiply(bigPrimes[pos]);
},
BigInteger::multiply);
}
}
I am using FPDF.php. I get an error when I try to create a PDF "FPDF error: Missing or incorrect image file: http://www.example.com/wp-content/uploads/2015/05/image.jpg"
In my error log I get this error:
PHP Warning: getimagesize(http://www.example.com/wp-content/uploads/2015/05/image.jpg): failed to open stream: Connection refused in /home/cluster-sites/2639/c/example.com/public_html/wp-content/themes/nameoftheme/includes/fpdf/fpdf.php on line 1213
I have set allow_url_fopen = ON in php.ini
I think it has something to do with the image path but I'm not sure what. It works fine on my test server.
My code is as follows:
//check if the query_string contains an ID
if(!isset($_REQUEST['id']))
{
header('Location:'.site_url());
exit();
}
//check if the ID is related to a WP_Post
$post = get_post($_REQUEST['id']);
if(empty($post))
{
header('Location:'.site_url());
exit();
}
//creating the brochure directory if not exists
if(!is_dir(ABSPATH.'wp-content/uploads/brochure'))
mkdir(ABSPATH.'wp-content/uploads/brochure');
$pdf_path = ABSPATH.'wp-content/uploads/brochure/'.$post->post_name.'.pdf';
$cache = false;
$debug = false;
//generating the pdf if not exists or older than the latest post update
if(!$cache || !is_file($pdf_path) || strtotime($post->post_modified) > filemtime($pdf_path))
{
require(get_template_directory().'/includes/fpdf/fpdf_enhanced.php');
global $imic_options;
$image_size = '600-400-size';
$pdf = new PDF_enhanced();
$pdf->AddFont('opensans','','opensans.php');
$pdf->AddFont('opensans','b','opensansb.php');
$pdf->AddFont('opensans','i','opensansi.php');
//$pdf->AddFont('opensans','eb','opensanseb.php');
//$pdf->AddFont('opensans','ebi','opensansebi.php');
$pdf->AddFont('opensans','l','opensansl.php');
//$pdf->AddFont('opensans','li','opensansli.php');
//$pdf->AddFont('opensans','s','opensanss.php');
//$pdf->AddFont('opensans','si','opensanssi.php');
$pdf->SetMargins(0, 0);
$property_sights = get_post_meta($post->ID, 'imic_property_sights', false);
//---------------------------------first page
$pdf->AddPage();
//main picture
$featured_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $image_size);
if(!empty($featured_image_url))
$pdf->Image($featured_image_url[0], 0, 0, 210, 0);
else if(!empty($property_sights))
{
$image = wp_get_attachment_image_src(array_shift($property_sights), $image_size);
$pdf->Image($image[0], 0, 0, 210, 0);
}
//left border
$pdf->SetFillColor(183, 132, 36);
$pdf->Rect(0, 0, 1.2, 297, 'F');
//property title
$pdf->SetFont('opensans', '', 30);
$pdf->SetTextColor(97, 33, 114);
$pdf->SetXY(20, 150);
$pdf->MultiCell(175, 12, $post->post_title, $debug);
//property address
$address = get_post_meta($post->ID, 'imic_property_site_address', true);
$pdf->SetFont('opensans', 'i', 20);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, 175);
$pdf->Cell(100, 12, $address, $debug);
//property price
$pdf->SetFont('opensans', 'b', 16);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(120, 180);
$pdf->MultiCell(60, 12, html_entity_decode(imic_get_currency_symbol($imic_options['currency-select'])).number_format(get_post_meta($post->ID, 'imic_property_price', true)), $debug, 'R');
//property number beds
$beds = get_post_meta($post->ID, 'imic_property_beds', true);
$pdf->SetFont('opensans', 'b', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, 200);
$pdf->Cell(30, 5.5, 'Number beds: ', $debug, 'L');
$pdf->SetFont('opensans', 'l', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(50, 200);
$pdf->Cell(20, 5.5, html_entity_decode($beds), $debug, 'L');
//property number of baths
$baths = get_post_meta($post->ID, 'imic_property_baths', true);
$pdf->SetFont('opensans', 'b', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, 208);
$pdf->Cell(36, 5.5, 'Number of baths: ', $debug, 'L');
$pdf->SetFont('opensans', 'l', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(56, 208);
$pdf->Cell(20, 5.5, html_entity_decode($baths), $debug, 'L');
//property floor area
$area = get_post_meta($post->ID, 'imic_property_area', true);
$pdf->SetFont('opensans', 'b', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, 216);
$pdf->Cell(23, 5.5, 'Floor area: ', $debug, 'L');
$pdf->SetFont('opensans', 'l', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(43, 216);
$pdf->Cell(20, 5.5, html_entity_decode($area.' Sq Ft'), $debug, 'L');
//property beachfront
$beachfront = get_post_meta($post->ID, 'imic_property_beachfront', true);
$pdf->SetFont('opensans', 'b', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, 224);
$pdf->Cell(25, 5.5, 'Beachfront: ', $debug, 'L');
$pdf->SetFont('opensans', 'l', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(45, 224);
$pdf->Cell(20, 5.5, html_entity_decode($beachfront), $debug, 'L');
//property freehold
$pdf->SetFont('opensans', 'b', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, 232);
$pdf->Cell(20, 5.5, 'Freehold: ', $debug, 'L');
$pdf->SetFont('opensans', 'l', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(40, 232);
$pdf->Cell(20, 5.5, 'Yes', $debug, 'L');
//property close to
$closeto = implode(', ', get_post_meta($post->ID, 'imic_property_closeto', true));
$pdf->SetFont('opensans', 'b', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, 240);
$pdf->Cell(19, 5.5, 'Close to: ', $debug, 'L');
$pdf->SetFont('opensans', 'l', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(39, 240);
$pdf->MultiCell(150, 5.5, html_entity_decode($closeto), $debug, 'L');
//logo
$pdf->Image($imic_options['logo_upload']['url'], 150, 270, 45, 0);
//---------------------------------second page
$pdf->AddPage();
//second page main picture
if(!empty($property_sights))
{
$image = wp_get_attachment_image_src(array_shift($property_sights), $image_size);
$pdf->Image($image[0], 0, 0, 210, 0);
}
//save the next image for the third page
$third_page_image = false;
if(!empty($property_sights))
$third_page_image =array_shift($property_sights);
$height = 142;
//thumbnails
if(!empty($property_sights))
{
$height += 58;
$image = wp_get_attachment_image_src(array_shift($property_sights), $image_size);
$pdf->Image($image[0], 0, 142, 69, 0);
if(!empty($property_sights))
{
$image = wp_get_attachment_image_src(array_shift($property_sights), $image_size);
$pdf->Image($image[0], 71, 142, 69, 0);
}
if(!empty($property_sights))
{
$image = wp_get_attachment_image_src(array_shift($property_sights), $image_size);
$pdf->Image($image[0], 142, 142, 69, 0);
}
}
else
$height += 10;
//property title
$pdf->SetFont('opensans', '', 15);
$pdf->SetTextColor(97, 33, 114);
$pdf->SetXY(20, $height);
$pdf->MultiCell(180, 12, $post->post_title, $debug);
//property address
$address = get_post_meta($post->ID, 'imic_property_site_address', true);
$pdf->SetFont('opensans', 'i', 15);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, $height + 10);
$pdf->Cell(200, 12, $address, $debug, 'L');
//property features
$height += 25;
$pdf->SetFont('opensans', 'i', 10);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(25, $height);
$pdf->Cell(100, 2, 'Features: ', $debug);
$property_amenities = get_post_meta($post->ID, 'imic_property_amenities', true);
foreach($property_amenities as $properties_amenity)
{
if($properties_amenity != 'Not Selected')
{
$pdf->SetFillColor(102, 102, 102);
$pdf->SetFont('opensans', 'l', 10);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(25, $height);
$pdf->Cell(100, 12, $properties_amenity, $debug);
$height += 5;
}
}
//---------------------------------third page
$pdf->AddPage();
//second page main picture
if(!empty($third_page_image))
{
$image = wp_get_attachment_image_src($third_page_image, $image_size);
$pdf->Image($image[0], 0, 0, 210, 0);
}
//rest of description
$description = $post->post_content;
$description = preg_replace("/(\r?\n){2,}/", "\n", $description);
$description = str_replace('’', '\'', $description);
$description = apply_filters( '$description', $post->post_content );
if(strlen($description) > 900)
$description = substr($description, 0, strpos($description, '.', 900)).'.';
$pdf->SetFont('opensans', 'l', 11);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(20, 145);
$pdf->MultiCell(170, 5.5, iconv("UTF-8", "CP1250//TRANSLIT", $description), $debug, 'L');
//separator
$pdf->SetFillColor(183, 132, 36);
$pdf->Rect(20, 234, 170, 0.7, 'F');
//contact title
$pdf->SetFont('opensans', 'i', 12);
$pdf->SetTextColor(183, 132, 36);
$pdf->SetXY(19, 234);
$pdf->Cell(20, 10, 'Example Name', $debug);
//contact details
$contact = "Building\n1st Street W.I.\ninfo#example.com\n+(1) 246 432 4663\nexample.com";
$pdf->SetFont('opensans', 'l', 9);
$pdf->SetTextColor(102, 102, 102);
$pdf->SetXY(19, 244);
$pdf->MultiCell(100, 4, $contact, $debug);
//---------------------------------fourth page
//save pdf
$pdf->Output($pdf_path);
}
//last check if the pdf exists
if(is_file($pdf_path))
{
//display pdf
header('Content-type: application/pdf');
readfile($pdf_path);
}
else
{
header('Location:'.site_url());
exit();
}
?>
I am using the graphaeljs library to display charts, at an ASP.NET MVC 4
I have copied this code from the graphaeljs website
<script src="scripts/raphael.js"></script>
<script src="scripts/g.raphael-min.js"></script>
<script src="scripts/g.bar-min.js"></script>
<script>
window.onload = function () {
var r = Raphael("holder"),
fin = function () {
this.flag = r.popup(this.bar.x, this.bar.y, this.bar.value || "0").insertBefore(this);
},
fout = function () {
this.flag.animate({ opacity: 0 }, 300, function () { this.remove(); });
},
fin2 = function () {
var y = [], res = [];
for (var i = this.bars.length; i--;) {
y.push(this.bars[i].y);
res.push(this.bars[i].value || "0");
}
this.flag = r.popup(this.bars[0].x, Math.min.apply(Math, y), res.join(", ")).insertBefore(this);
},
fout2 = function () {
this.flag.animate({ opacity: 0 }, 300, function () { this.remove(); });
},
txtattr = { font: "12px sans-serif" };
r.text(160, 10, "Single Series Chart").attr(txtattr);
r.text(480, 10, "Multiline Series Stacked Chart").attr(txtattr);
r.text(160, 250, "Multiple Series Chart").attr(txtattr);
r.text(480, 250, "Multiline Series Stacked Chart\nColumn Hover").attr(txtattr);
r.barchart(10, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10]]).hover(fin, fout);
r.hbarchart(330, 10, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], { stacked: true }).hover(fin, fout);
r.hbarchart(10, 250, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]]).hover(fin, fout);
var c = r.barchart(330, 250, 300, 220, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], { stacked: true, type: "soft" }).hoverColumn(fin2, fout2);
};
</script>
But when I run at my browser, this message appears
Uncaught TypeError: Cannot read property 'x' of undefined raphael.js:11
c._engine.create raphael.js:11
c raphael.js:9
window.onload (index):92
I do not know what I do wrong, and I used the libraries exactly as they are. Can you please tell me, what might be my mistake?
Sorry, I don't see anything wrong with the code you posted.
I made a fiddle for you.
It is obviously an issue with the raphael.js file.
Be sure to include class="raphael" on your body tag, and a div with id="holder".
If that fails, try re-downloading raphael.js.
I could not figure out how to dereference this pointer...
sizeof(shapetest2->tripsName) in this line below, it is obviously not going to work because it is a pointer, i could not figure out how to dereference it? (is it easy? or is it a couple steps?, i've tried several things, but could not get close) I am not an experience enough coder to figure this particular circumstance out.
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(shapetest2->tripsName), shapetest2->tripsName);
here is the setup code. (i am experimenting with a VOB in openGL ES 1.5, so if it looks odd, that is why) if i forgot some important setup or definitions, or code, let me know and i'll include it.
GLsizeiptr dataSize;
GLsizeiptr indexSize;
typedef struct shapeBase {
void *stripsName[maxStrips];
void *tripsName;
void *fansName;
int totStrips;
int stripsNum[maxStrips];
int tripsNum;
int totFans;
int fansBgn[maxStrips];
int fansNum[maxStrips];
void *dataName;
void *listOfInserts;
Vertex3D center;
Vertex3D radius;
int damageMax;
float weight;
GLuint bufferName;
GLuint indexName;
} shapeBase;
static const GLushort test2Trips[] =
{
0, 1, 3, 1, 2, 3,
4, 5, 7, 5, 6, 7,
8, 9, 11, 9, 10, 11,
12, 13, 15, 13, 14, 15,
16, 17, 19, 17, 18, 19,
20, 21, 23, 21, 22, 23,
24, 25, 27, 25, 26, 27,
28, 29, 31, 29, 30, 31,
32, 33, 35, 33, 34, 35,
36, 37, 39, 37, 38, 39,
40, 41, 43, 41, 42, 43,
44, 45, 47, 45, 46, 47,
};
//-------------------------
static inline void shapetest2Setup(void)
{
shapetest2 = malloc(sizeof(shapeBase));
shapetest2->stripsName[1] = NULL;
shapetest2->tripsName = &test2Trips;
shapetest2->fansName = NULL;
shapetest2->dataName = &test2Data;
shapetest2->totStrips = 0;
shapetest2->stripsNum[1] = 0;
shapetest2->tripsNum = 72;
shapetest2->totFans = 0;
shapetest2->listOfInserts = NULL;
shapetest2->center = Vertex3DMake( 0.000000, -0.000000, 2.000000 );
shapetest2->radius = Vertex3DMake( 1.000000, 1.000000, 2.000000 );
dataSize = sizeof(test1Data) + sizeof(test2Data);
glGenBuffers(1, &mainBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glBufferData(GL_ARRAY_BUFFER, dataSize, NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(test1Data), test1Data);
glBufferSubData(GL_ARRAY_BUFFER, sizeof(test1Data), sizeof(test2Data), test2Data);
// glGenBuffers(1, &shapetest2->indexName);
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, shapetest2->indexName);
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(test2Trips), test2Trips, GL_STATIC_DRAW);
indexSize = sizeof(test1Trips) + sizeof(test2Trips);
glGenBuffers(1, &mainIndex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mainIndex);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize, NULL, GL_STATIC_DRAW);
}
//------------------------------------------------------
static inline void DrawOutShape(void)
{
glBindBuffer(GL_ARRAY_BUFFER, mainBuffer);
glVertexPointer(3, GL_FLOAT, sizeof(VertexData3D), (void*)0);
glNormalPointer(GL_FLOAT, sizeof(VertexData3D), (void*)12);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mainIndex);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(theInsert->insertName->tripsName), theInsert->insertName->tripsName);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(test1Trips), test1Trips);
// glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, sizeof(test1Trips), sizeof(test2Trips), shapetest2->tripsName);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(shapetest2->tripsName), shapetest2->tripsName);
glDrawElements(GL_TRIANGLES, theInsert->insertName->tripsNum, GL_UNSIGNED_SHORT, (void*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
polys += theInsert->insertName->tripsNum;
}
(theInsert is a handle (pointer to pointer) of the shapetest2, so you can substitute shapetest2 if you see "theInsert->insertName")
if i comment out the offending line, and uncomment the line above, it is working, but i need this indirection, (and actually i need another level of indirection that you can see in another commented out line) but if i can figure out how to dereference this line, i should be able to do it for another level of indirection?)
sizeof is compile-time constant that works on exact type you provide. sizeof of void* is just a size of pointer on your machine (likely 4/8 bytes). Just store size along with other data.