Skip to content

Instantly share code, notes, and snippets.

@tobbbe
tobbbe / node-file-log.js
Last active February 21, 2023 07:46
log quick but (very) dirty file logger
require('fs').writeFile(
require('path').join(process.cwd(), '/.tob.log'),
JSON.stringify(_DATA_, null, 4),
(err)=>{if (err) console.log(err)}
)
@tobbbe
tobbbe / asp-net-cors.md
Last active June 14, 2022 09:33
allow CORS in mvc .net

1. Install nuget: Microsoft.AspNet.WebApi.Cors

Install-Package Microsoft.AspNet.WebApi.Cors (in umbraco core project)

(WARNING! This will install latest version of .net mvc webapi => which may fuck up things if your stuff has dependencies to older versions of MVC webapi)

2. Add a FileeeNameee.cs with:

@tobbbe
tobbbe / tailwind-no-js-slider.tsx
Created November 15, 2021 08:45
A slider without any js
import React from 'react';
import Image from 'next/image';
export function Slider() {
const sliderRef = React.useRef<HTMLDivElement>(null);
const [activeIndex, setAciveIndex] = React.useState(0);
function setActive(i: number) {
sliderRef.current?.scrollTo((sliderRef.current.scrollWidth / quotes.length) * i, 0);
}
@tobbbe
tobbbe / Portal.cshtml
Last active August 30, 2021 12:03
create-react-app in umbraco (or any asp.net website)
@{
Layout = null;
}
<!-- OVERWRITE BELOW THIS LINE -->
@tobbbe
tobbbe / Umbraco web api file import (to use with ng-file-upload)
Last active August 26, 2021 12:39
umbraco web api file import (to use with ng-file-upload)
Requeires ng-file-upload https://github.com/danialfarid/ng-file-upload/
Dont forgett to inject into app module 'ngFileUpload'
Use in template: <file-uploader></file-uploader>
@tobbbe
tobbbe / google maps iframe
Created July 10, 2014 09:24
google maps iframe
@{
var longitude = Location.Longitude.ToString() ?? null;
var latitude = Location.Latitude.ToString() ?? null;
var googlemapSource = "https://www.google.com/maps/embed/v1/";
if (!string.IsNullOrEmpty(latitude) && !string.IsNullOrEmpty(longitude))
{
// map mode
googlemapSource += "place?";
const debug = true;
function debugLog(message) {
if (debug) {
console.log(message);
}
}
let sharedCached: { [key: string]: IKachelerCacheItem<unknown> } = {};
export const kacheler = {
import { Injectable, Injector } from '@angular/core';
import { HttpErrorResponse, HttpHandler, HttpInterceptor, HttpRequest, HttpEvent, HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { ErrorObservable } from 'rxjs/Observable/ErrorObservable';
import { EmptyObservable } from 'rxjs/Observable/EmptyObservable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { catchError, filter, take, switchMap, finalize } from "rxjs/operators";
import { APIURL } from "../app/constants";
import { UserService } from "./user/user.provider";
@tobbbe
tobbbe / bookmarklet
Last active April 27, 2020 20:07
get list of spotify links from slack channel
javascript:!function(){const SLACK_BOT_TOKEN="your slack bot token";async function get(a=[],b){let c=`https://slack.com/api/conversations.history?token=${SLACK_BOT_TOKEN}&channel=CJTD5RP7Y`;b&&(c+="&cursor="+b);const d=await fetch(c),e=await d.json();return a=[...a,...e.messages],e.has_more?await get(a,e.response_metadata.next_cursor):a}async function init(){const a=await get(),b=a.reduce((a,b)=>{try{const c=b.text.split("com/track/")[1].split("?")[0],d=`https://open.spotify.com/track/${c}`;a.arr.push(d),a.str+=`${d}\n`}catch{}return a},{arr:[],str:""});console.log(b);var c=window.open();const d=c.document.createElement("textarea");d.value=b.str,d.style="width:100%;height: 600px;font-size: 16px",c.document.body.innerHTML=`<p>${b.arr.length} tracks</p>`,c.document.body.appendChild(d)}init();}();
@tobbbe
tobbbe / bookmarklet
Last active February 7, 2020 16:40
copy list items from trello
javascript:!function(){let e=prompt("Ange namn på listan du vill kopiera");e&&(e=e.toLowerCase().trim());let t=$(".list-header-name-assist").filter((t,n)=>n.innerHTML.toLowerCase()===e).first().closest(".list").find(".list-card-title").contents().toArray().filter(e=>3===e.nodeType).map(e=>e.data).reduce((e,t)=>(e.text=`${e.text}${t}\n`,e),{html:"",text:""});var n=window.open();const o=n.document.createElement("textarea");o.value=t.text,o.style="width:100%;height: 600px;font-size: 16px",n.document.body.appendChild(o),o.select(),n.document.execCommand("copy")}();