This file contains hidden or 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
| fn modify_url(caps: &Captures, host: &str, port: u16) -> Option<String> { | |
| let first_match = caps.iter().nth(0)?; | |
| let match_item = first_match?; | |
| if let Ok(mut url) = Url::parse(match_item.as_str()) { | |
| // The following 2 method calls will mutate | |
| // the url, but return *different* Errors if they fail | |
| // | |
| // Because I don't care about the actual error, only | |
| // if it succeeded or failed, you can convert a Result |
This file contains hidden or 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
| pub fn replace_host<'a>(bytes: &'a str, host_to_replace: &'a str, target_host: &'a str, target_port: u16) -> Cow<'a, str> { | |
| let matcher = format!("https?://{}", host_to_replace); | |
| Regex::new(&matcher) | |
| .unwrap() | |
| .replace_all(bytes, | |
| |item: &Captures| | |
| modify_url(item, target_host, target_port).unwrap_or(String::from(""))) | |
| } | |
| fn modify_url(caps: &Captures, host: &str, port: u16) -> Option<String> { |
This file contains hidden or 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
| pub fn replace_host<'a>(bytes: &'a str, host_to_replace: &'a str, target_host: &'a str, target_port: u16) -> Cow<'a, str> { | |
| let matcher = format!("https?://{}", host_to_replace); | |
| Regex::new(&matcher).unwrap().replace_all(bytes, |item: &Captures| main_replace(item, target_host, target_port)) | |
| } | |
| fn main_replace(caps: &Captures, host: &str, port: u16) -> String { | |
| caps.iter().nth(0) | |
| .map_or(String::from(""), | |
| // here there was a regex match | |
| |capture_item| capture_item.map_or(String::from(""), |
This file contains hidden or 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
| <?php | |
| namespace Graham\FabricSamples\Controller\Order; | |
| use Magento\Framework\App\Action\Action; | |
| use Magento\Framework\App\ResponseInterface; | |
| use Magento\Framework\Controller\ResultFactory; | |
| class Form extends Action | |
| { | |
| /** |
This file contains hidden or 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
| <?php | |
| namespace Graham\FabricSamples\Controller\Order; | |
| use Magento\Framework\App\Action\Action; | |
| use Magento\Framework\App\ResponseInterface; | |
| use Magento\Framework\Controller\ResultFactory; | |
| class Form extends Action | |
| { | |
| /** |
This file contains hidden or 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
| /** | |
| * Look 👀 - no types anywhere, but still getting the | |
| * best type checking Typescript has to offer :) | |
| */ | |
| define(['jquery'], function($) { | |
| // Typescript knows this is JQuery here so can provide type | |
| // safety on all of it's methods | |
| console.log($.ajax); |
This file contains hidden or 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
| /** | |
| * This is a mapped type I would maintain manually | |
| */ | |
| interface DefineTypes { | |
| "jquery": JQueryStatic, | |
| "underscore": Underscore | |
| } | |
| /** | |
| * This is an example of the 'define' function from requirejs, where it would take |
This file contains hidden or 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
| /** | |
| * This is a mapped type I would maintain manually | |
| */ | |
| interface DefineTypes { | |
| "jquery": JQueryStatic, | |
| "underscore": Underscore | |
| } | |
| /** | |
| * This is an example of the 'define' function from requirejs, where it would take |
This file contains hidden or 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
| type MyType = El + serde::Serialize; | |
| fn debug<MyType>(field: &MyType) { | |
| match serde_json::to_string(field) { | |
| Ok(j) => { | |
| let text_area = TextArea { | |
| name: "output".into(), | |
| value: j.into() | |
| }; | |
| form_builder::document.body().append_child(text_area.build()); |
This file contains hidden or 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
| <?php | |
| /** | |
| * Menu template | |
| * | |
| * @var $block \Ves\Megamenu\Block\Menu | |
| */ | |
| ?> | |
| <?php | |
| if ($menu = $this->getMenu()) { | |
| $html = $classes = ''; |