I want to make a get request to url in rego. But it raises Invalid parameter: unallowed built-in function call in rego module: http.send error
Here is my code.
package play
default hello = false
hello {
response := http.send({
"method" : "GET",
"url": "http://localhost:8181/v1/data/example"
})
}
What I'm doing wrong?
That example is correct however https://play.openpolicyagent.org does not permit the http.send function for security reasons. Try it locally.
$ opa run
Inside the REPL:
> http.send({"method": "get", "url": "https://example.com"})
{
"body": null,
"raw_body": "\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n \u003ctitle\u003eExample Domain\u003c/title\u003e\n\n \u003cmeta charset=\"utf-8\" /\u003e\n \u003cmeta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" /\u003e\n \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /\u003e\n \u003cstyle type=\"text/css\"\u003e\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: -apple-system, system-ui, BlinkMacSystemFont, \"Segoe UI\", \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 2em;\n background-color: #fdfdff;\n border-radius: 0.5em;\n box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n #media (max-width: 700px) {\n div {\n margin: 0 auto;\n width: auto;\n }\n }\n \u003c/style\u003e \n\u003c/head\u003e\n\n\u003cbody\u003e\n\u003cdiv\u003e\n \u003ch1\u003eExample Domain\u003c/h1\u003e\n \u003cp\u003eThis domain is for use in illustrative examples in documents. You may use this\n domain in literature without prior coordination or asking for permission.\u003c/p\u003e\n \u003cp\u003e\u003ca href=\"https://www.iana.org/domains/example\"\u003eMore information...\u003c/a\u003e\u003c/p\u003e\n\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n",
"status": "200 OK",
"status_code": 200
}
Related
Well, I am developing my own Content Management System using ASP.NET MVC and for a page builder I've decided to use GrapeJS. Now, since this is new to me, I can't seem to find a way to save the pages I would have assembled using GrapeJS. I have used the gjs-preset-webpage GrapeJS plugin and the only JavaScript for the assembling area I have is as shown below:
<script type="text/javascript">
var editor = grapesjs.init({
height: '100%',
showOffsets: 1,
noticeOnUnload: 0,
storageManager: { autoload: 0 },
container: '#gjs',
fromElement: true,
plugins: ['gjs-preset-webpage'],
pluginsOpts: {
'gjs-preset-webpage': {}
}
});
</script>
The HTML I've used is as follows as well:
<div id="gjs" style="height:0px; overflow:hidden">
<div class="panel">
<h1 class="welcome">Welcome to</h1>
<div class="big-title">
<svg class="logo" viewBox="0 0 100 100">
<path d="M40 5l-12.9 7.4 -12.9 7.4c-1.4 0.8-2.7 2.3-3.7 3.9 -0.9 1.6-1.5 3.5-1.5 5.1v14.9 14.9c0 1.7 0.6 3.5 1.5 5.1 0.9 1.6 2.2 3.1 3.7 3.9l12.9 7.4 12.9 7.4c1.4 0.8 3.3 1.2 5.2 1.2 1.9 0 3.8-0.4 5.2-1.2l12.9-7.4 12.9-7.4c1.4-0.8 2.7-2.2 3.7-3.9 0.9-1.6 1.5-3.5 1.5-5.1v-14.9 -12.7c0-4.6-3.8-6-6.8-4.2l-28 16.2" />
</svg>
<span>GrapesJS</span>
</div>
<div class="description">
This is a demo content from index.html. For the development, you shouldn't edit this file, instead you can
copy and rename it to _index.html, on next server start the new file will be served, and it will be ignored by git.
</div>
</div>
<style>
.panel {
width: 90%;
max-width: 700px;
border-radius: 3px;
padding: 30px 20px;
margin: 150px auto 0px;
background-color: #d983a6;
box-shadow: 0px 3px 10px 0px rgba(0,0,0,0.25);
color: rgba(255,255,255,0.75);
font: caption;
font-weight: 100;
}
.welcome {
text-align: center;
font-weight: 100;
margin: 0px;
}
.logo {
width: 70px;
height: 70px;
vertical-align: middle;
}
.logo path {
pointer-events: none;
fill: none;
stroke-linecap: round;
stroke-width: 7;
stroke: #fff
}
.big-title {
text-align: center;
font-size: 3.5rem;
margin: 15px 0;
}
.description {
text-align: justify;
font-size: 1rem;
line-height: 1.5rem;
}
</style>
</div>
Now that I have embedded it into my project and can assembled pages using it, I can't seem to find how to save or where would the assembled page be to be saved. Can anyone help me?
You need a endpoint to allow grapes' storage manager to send your site current status information. I save the json and html just in case, but I think json is enough. Well then you setup your storage manager.
const editor = grapesjs.init({
storageManager:{
type: 'remote',
autosave: true, // Store data automatically
urlStore: 'YOUR_ENDPOINT_URL',
}
});
You will get a call to your endpoint every time something changes with the following parameterts:
gjs-assets: Assets array
gjs-components: Object with markup definition of your site
gjs-styles: Object with styles definition
gjs-html: your site HTML
gjs-css: your CSS
Just be sure to inject this definitions when initialising grapes as well:
const editor = grapesjs.init({
components: "YOUR_STORED_COMPONENTS_HERE",
style: "YOUR_STORED_CSS_HERE",
storageManager:{
type: 'remote',
autosave: true, // Store data automatically
urlStore: 'YOUR_ENDPOINT_URL',
}
});
For further information: Docs
I have installed wkhtmltopdf 0.12.3 (with patched qt) on my desktop machine and the exact same version on my Centos virtual machine.
I am using WickedPDF and Rails to convert HTML to PDF.
When the PDF is generated it has slight differences in the font. Some weird letter spacing. I have attached images showing this.
You can see the gap between the e and n this however is not present on my local machine. Image below:
Does anyone know why this would happen?
Any advice would be appreciated.
Thanks
This is the Ruby code which I am using to generate the PDF with WickedPDF
def generate_pdf
pdf = WickedPdf.new
pdf_file = pdf.pdf_from_string(ActionController::Base.new().render_to_string('card_requests/show.pdf.haml', layout: 'pdf', locals: {card_request: self}),
dpi: '300',
margin: {top: 0, bottom: 0, left: 0, right: 0},
page_height: '2.25in',
page_width: '3.75in',
disable_smart_shrinking: false
)
tempfile = Tempfile.new(["#{self.name.gsub(' ', '_').downcase}_biz_card", '.pdf'], Rails.root.join('pdfs'))
tempfile.binmode
tempfile.write pdf_file
tempfile.close
self.pdf = File.open(tempfile.path)
tempfile.unlink
self.save
end
Here is also the show.pdf.haml file with the CSS at the top:
!!! 5
%html
%head
:css
html * {
margin: 0 !important;
padding: 0 !important;
page-break-inside: avoid !important;
}
body {
margin: 0 !important;
padding: 0 !important;
page-break-inside: avoid !important;
text-rendering: optimize-speed;
}
.card-preview {
font-family: 'TradeGothic';
background-size: contain;
width: 369px;
height: 220px;
page-break-after: avoid !important;
position: relative;
}
#card-name {
color: #ED1D27;
font-weight: bold;
font-size: 12pt;
position: absolute;
top: 37px;
left: 39px;
width: 328px;
}
#card-title {
color: #2E2D2D;
font-weight: bold;
position: absolute;
top: 54px;
left: 39px;
font-size: 9pt;
}
#card-office-phone {
color: #4e4e48;
position: absolute;
top: 148px;
left: 39px;
font-size: 8.5pt;
}
#card-cell-phone {
color: #4e4e48;
position: absolute;
top: 135px;
left: 39px;
font-size: 8pt;
width: 200px;
}
#card-email {
color: #4e4e48;
position: absolute;
top: 161px;
left: 39px;
font-size: 8.5pt;
}
#card-website {
color: #4e4e48;
position: absolute;
top: 174px;
left: 39px;
font-size: 8pt;
}
.hide {
display: none;
}
%meta{:charset => "utf-8"}
%body
.card-preview{style: "background-image: url('#{Rails.root.join('app', 'assets', 'images', 'card_template_2.svg')}')"}
#card-name
= card_request.name
#card-title
= card_request.title
#card-office-phone{class: (card_request.office? ? "" : 'hide')}
== office 555 555 5555 #{card_request.ext? ? "ext #{card_request.ext_phone}" : ''}
#card-cell-phone{class: ((card_request.cell? && !card_request.cell_phone.blank?) ? "" : 'hide'), style: (card_request.office? ? "" : 'top: 148px; left: 39px;')}
= (card_request.cell? ? "cell 555 555 5555" : '')
#card-email
= card_request.email
#card-website
www.website.com
I have since fixed this issue by following this:
https://taskman.eionet.europa.eu/issues/20890
It fixes kerning issue on CentOS for me.
I was facing a similar issue of spaces after certain specific letters like
Reg istration ---> space after letter 'g'
O pen ---> space after Capital letter 'O'
The above issue could be due to system specific fonts configs. I referred an issue reported over github for the same https://github.com/wkhtmltopdf/wkhtmltopdf/issues/45
This issue occurs on a production instance (AWS AMI linux) with CentOS 6.x but was working perfectly with ubuntu 14.04. I looked into the system fonts configs 51-local.conf over CentOS at path /etc/fonts/conf.d .If there is no file with name wkhtmltopdf at the same path then use the default fonts file 51-local.conf to have the below configuration as custom fonts.
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hintstyle">
<const>hintslight</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>
<match target="font">
<edit mode="assign" name="lcdfilter">
<const>lcddefault</const>
</edit>
</match>
</fontconfig>
Also, If you are using wicked_pdf.rb initializer configuration exec path as /usr/local/bin/wkhtmltopdf for development environment. try to replace the path with /bin/wkhtmltopdf for production bundle
I have been looking for a solution for embedding Twitter user profiles, but have come up empty so far. What I'm looking for is something similar to how Twitter pops up a nice profile overview when you click a username on twitter.com. I took a screencap of my profile so you can see below what I'm talking about.
I don't have any need for the user timeline or anything like that, just the user info, the cover photo background would be nice as well as a link to follow the person. I took a look through Twitters embed code builder but there didn't seem to be anything that really fit the bill. I am using Wordpress so a plugin solution could be viable, but if it's just a code embed that is fine as well.
There is currently no embed functionality that I know of for the profile summary, however you can call the api to get profile information from Twitter in two ways:
For one use at a time: /users/show, or
For up to 100 users at once: /users/lookup
You can then take the returned json and style it to match the twitter format or any other style you wish.
Not really embed but this could work for you too https://dev.twitter.com/web/intents#user-intent
Here is an implementation for the button, this require some work to add the profile picture and the background picture
Icon SVG code:
<symbol id="twitter" viewBox="0 0 512 512"><path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z" /></symbol>
SASS/CSS:
.twitter a
font-family: "Roboto", "Noto Sans", "Open Sans", "sans-serif"
display: inline-flex
color: #fff
border-radius: 5px
background: #1b95e0
padding: .4em .8em
text-decoration: none
font-weight: bold
text-align: left
HTML:
<div class="twitter" style="height: 35px; width: 240px;"><a target="_blank" rel="noopener noreferrer" href="https://twitter.com/LinuxHacksOrg">
<svg height="20px" width="20px" style="margin-right: 5px; fill: #fff;">
<use xlink:href="/assets/imgs/res/icons-full.svg#twitter"></use></svg>
Follow us #LinuxHacksOrg</a></div>
<style>
.twitter a {
font-family: "Roboto", "Noto Sans", "Open Sans", "sans-serif";
display: inline-flex;
color: #fff;
border-radius: 5px;
background: #1b95e0;
padding: .4em .8em;
text-decoration: none;
font-weight: bold;
text-align: left;
}
</style>
<div class="twitter" style="height: 35px; width: 300px;"><a target="_blank" rel="noopener noreferrer" href="https://twitter.com/LinuxHacksOrg">
<svg height="20px" width="20px" style="margin-right: 5px; fill: #fff;" viewBox="0 0 512 512" preserveAspectRatio="none">
<path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z" />
</svg>
Follow us #LinuxHacksOrg</a></div>
I'm using jquery ui autocomplete in my site and it lists all product's name in the search box...i m firing a query to the database and retrieving the results...thats not my problem....
My problem is i need to trim the lengthy products name to the size of the width of autocomplete box(currently i have set it to 180px) and add three dots("..." i.e. an ellipsis)...
I have tried this css style in a normal div elemnt and its working fine..but when i try to integrate this to my autocomplete plugin it is not working...
I dont know what is the problem...or is there any other way to apply this ellipsis to lists...
css style for autocomplete is,
<style>
.ui-autocomplete {
max-height: 200px;
max-width: 180px;
overflow-y:scroll;
text-wrap: none;
white-space:nowrap;
text-overflow:ellipsis;
overflow:hidden;
}
</style>
here text-overflow:ellipsis; does the trick
*Note:*I dont need a horizontal scroll as a solution for this problem...
here is working examples,
http://jsfiddle.net/FLmfH/
but here its not working when added to jquery ui plugin...any suggestions or workarounds for this problem?...
You just need to set the overflow and text-overflow on the .ui-menu .ui-menu-item a like this:
.ui-menu .ui-menu-item a {
text-overflow: ellipsis;
overflow: hidden;
}
Example: Fiddle
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"AAAAaaaaPP PppLLLlll EEEeeeeeee",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"JaaaaaAAAAvvvvVVVVVvAAAAaaaaaaaaaa",
"Lisp",
"Perl",
"PHP",
"O oooOoOOoooOOOoo ooOo ooO ooooOoooO ooo oOooooo ooO o oOoooOooOoooOooOoooOoooooo oooooOOoooo oOoooooOo ooooooOoooooooOoO",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$("#tags").autocomplete({
source: availableTags
});
});
.ui-autocomplete {
max-height: 200px;
max-width: 180px;
overflow-y: scroll;
overflow-x: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding-right: 20px;
}
.ui-menu .ui-menu-item a {
text-overflow: ellipsis;
overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<div class="ui-widget">
<label for="tags">Tags:</label>
<input id="tags" />
</div>
I've tried to replace the styles of link on my site, and it seems like the font face is replaced successfully, but it's not taking in the color and text-decoration. Here is my script:
<script type="text/javascript">var archermed = {src: 'archermed.swf'}; sIFR.activate(archermed);sIFR.replace(archermed, {selector: '.CollectionTopTabHdr',css: '.sIFR-root {font-size:14px; color:#663399; text-decoration; font-weight:normal; margin:0;} a, a:link, a:visited, a:active {color:#663399; text-decoration:none;}',wmode: 'transparent'});</script>
here is my HTML code:
<div class="CollectionTopTabHdr">LINK</div>
Thanks in advance!
18fis
I found out from another question that I need to separate out the link states in css, so here is what I did, and it works now!:
sIFR.replace(archerbold, {selector: '.sifrHeader',css: ['.sIFR-root { font-size:14px; color: #663399;}','a { text-decoration: none; color: #663399; }','a:link { color: #663399; }','a:hover { color: #663399; }','a:active {color:#663399;}'],offsetTop: -1, tuneHeight: 0,wmode: 'transparent', forceSingleLine: true});