Skip to content

Instantly share code, notes, and snippets.

View shakyShane's full-sized avatar

Shane Osbourne shakyShane

View GitHub Profile
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
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> {
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(""),
<?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
{
/**
<?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
{
/**
/**
* 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 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 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
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());
<?php
/**
* Menu template
*
* @var $block \Ves\Megamenu\Block\Menu
*/
?>
<?php
if ($menu = $this->getMenu()) {
$html = $classes = '';