Skip to content

Instantly share code, notes, and snippets.

View tvaisanen's full-sized avatar

Toni Väisänen tvaisanen

View GitHub Profile
@tvaisanen
tvaisanen / web-component-sample.cljs
Created May 10, 2022 16:41
ClojureScript Web Component: Extend js/HTMLElement
(defn MyElement
{:jsdoc ["@constructor"]}
[t]
;; class MyElement extends HTMLElement {}
(js/Reflect.setPrototypeOf
(.-prototype MyElement)
(.-prototype js/HTMLElement))
(js/Reflect.setPrototypeOf
MyElement
(ns project.auth0
(:require [re-frame.core :as rf]
[ajax.core :as ajax]
["@auth0/auth0-spa-js" :as spa]
[reitit.frontend.easy :as rfe]
[clojure.string :as str])
(:import [goog.history Html5History]))
(defonce client
(defn stream-bytes
"Input stream to bytes. i.e. (-> file io/input-stream stream-bytes)"
[is]
(let [baos (java.io.ByteArrayOutputStream.)]
(io/copy is baos)
(.toByteArray baos)))
fn uncapitalize_first_from_string(name: &String) -> String {
let mut result = String::new();
let _name_len = name.len();
for (i, c) in name.chars().enumerate() {
match i == 0 {
true => {
let mut lower = c.to_lowercase();
result.push(lower.next().unwrap())
},
false => result.push(c)
fn component_name_to_dashed(name: &String) -> String {
let mut dashed:String = String::new();
let camel_catcher: Regex = Regex::new(r"([A-Z][a-z]*)").unwrap();
let words: Vec<&str> = camel_catcher.find_iter(name)
.map(|match_| match_.as_str())
.collect();
fn component_name_to_dashed(name: &String) -> String {
println!("{}",name);
let dashed = name.clone();
dashed
}
#[test]
fn component_name_to_dashed_works(){
let camel: String = "ComponentName".to_string();
let expected = "component-name".to_string();
extern crate handlebars;
#[macro_use]
extern crate serde_json;
use handlebars::Handlebars;
use std::path::Path;
use std::error::Error;
use std::fs::OpenOptions;
use std::io::prelude::*;
import React from 'react';
import {connect} from 'react-redux';
import { Container } from "./{component-name}.styled";
import * as actions from "./{component-name}.actions";
type Props = {};
const ComponentName = (props: Props) => {
return <Container />
};
use std::fs::OpenOptions;
fn main() {
// read the command line arguments
// and skip the first one, which
// is the command itself
for arg in std::env::args().skip(1) {
// get the filename from arg
import * as productActions from '../../state/search-results/search-results.actions';
export function makeSearch(keyword) {
// by using redux-thunk middleware
// async redux action can be handled
return function (dispatch, getState) {
// get the promise
const promise = fetch("http://api.url/");