Skip to content

Instantly share code, notes, and snippets.

View shakyShane's full-sized avatar

Shane Osbourne shakyShane

View GitHub Profile
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 = '';
<div class="subnav__col"><a class="subnav__title subnav__title--underling-01" href="{{config path="web/secure/base_url"}}furniture">Furniture</a>
<ul class="subnav__list subnav__list--featured">
<li class="subnav__item nav-2-1"><a class="subnav__link" href="{{config path="web/secure/base_url"}}furniture/view-all-furniture">View All</a></li>
<li class="subnav__item nav-2-2"><a class="subnav__link" href="{{config path="web/secure/base_url"}}furniture/new-in-furniture">New In</a></li>
<li class="subnav__item nav-2-3"><a class="subnav__link subnav__link--divider" href="{{config path="web/secure/base_url"}}furniture/bestsellers-furniture">Bestsellers</a></li>
<li class="subnav__item nav-2-4"><a class="subnav__link" href="{{config path="web/secure/base_url"}}furniture/bone-inlay">Bone Inlay Collection</a></li>
<li class="subnav__item nav-2-5"><a class="subnav__link" href="{{config path="web/secure/base_url"}}furniture/mother-of-pearl">Mother of Pearl Collection</a></li>
// this is the 'interface'
trait Callable {
fn step(&self) -> Result<(), String>;
fn rollback(&self) -> Result<(), String>;
}
// this is an enum that's constrained to only
// structs that implement 'Callable'
#[derive(Debug)]
enum Task<T: Callable> {