Skip to content

Instantly share code, notes, and snippets.

View shakyShane's full-sized avatar

Shane Osbourne shakyShane

View GitHub Profile

config-gen

Generate RequireJS Optimizer configuration for Magento 2 website based on real-world usage.

Step 1 - Download the binary

config-gen is packaged as a single binary (currently only osx) to enable easy usage, just check the releases page and download the latest.

config-gen

Generate RequireJS Optimizer configuration for Magento 2 website.

Step 1 - Download the binary

config-gen is packaged as a single binary (currently only osx) to enable easy usage, just check the releases page and download the latest.

struct AppState {
config: Arc<Mutext<Vec<String>>>
}
///
/// these handlers can be running on any number of threads
///
fn handler(req: &HttpRequest<AppState>) -> Box<Future<Item = HttpResponse, Error = ()>> {
// clone the Arc here so it can be safely moved into the closure
impl M2PresetOptions {
pub fn get_opts(prog_config: ProgramConfig) -> Option<M2PresetOptions> {
serde_yaml::from_value(prog_config.get_opts("m2")?).ok()?
}
}
///
/// A simple way to apply both a predicate
/// and default value when dealing with an option.
///
fn is_legal(age: Option<usize>) -> bool {
age.map(|x| x >= 18).unwrap_or(false)
}
version: '2'
services:
nginx:
volumes:
- .docker/certs:/etc/letsencrypt
env_file:
- ./.docker/local.env
php:
<!-- app/code/Simmi/Theme/view/frontend/web/template/account.html -->
<div data-bind="text: loadingText"></div>
@shakyShane
shakyShane / account.html
Created August 22, 2018 08:27
Ui Component example
<div class="global-underlay"
data-bind="
css: {'global-underlay--active': state().underlayActive},
click: close
"
></div>
<div class="global-overlay"
data-bind="
css: {
'global-overlay--active': state().overlayActive,
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> {