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 / 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);
}
const debug = true;
function debugLog(message) {
if (debug) {
console.log(message);
}
}
let sharedCached: { [key: string]: IKachelerCacheItem<unknown> } = {};
export const kacheler = {
@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")}();
@tobbbe
tobbbe / ReturnRawString.cs
Created October 1, 2019 13:35
return raw string from web api controller
[HttpGet]
public HttpResponseMessage ReturnRawString()
{
return new HttpResponseMessage()
{
Content = new StringContent(
Something.CreateString(),
Encoding.UTF8,
"text/plain"
)
@tobbbe
tobbbe / comparejson.cs
Created September 16, 2019 13:09
compare json objects equality
[HttpGet]
public IHttpActionResult CompareJsons()
{
var jsonString1 = "{\"key1\" : [{a:\"ABC\"}, {b:\"ABd\"}, ], \"key2\":\"DEF\"}";
var jsonString2 = "{ \"key2\":\"DEF\" , \r\n \t \"key1\" : [{a:\"ABC\"}, {b:\"ABd\"}] }";
var obj1 = JToken.Parse(jsonString1);
var obj2 = JToken.Parse(jsonString2);
var comparer = new JTokenEqualityComparer();
@tobbbe
tobbbe / csv-file-export.cs
Last active September 24, 2019 06:10
export string to csv file web api umbraco
public class ExportController
{
[HttpGet]
public HttpResponseMessage AllUsers()
{
var csv = new StringBuilder();
var fileName = $"export {DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss")}.csv";
var result = new HttpResponseMessage(HttpStatusCode.OK);
var excelDateTimeFormat = "yyyy-MM-dd HH:mm:ss"; // format datetimes so excel can parse them
public class Import
{
private static object ImportLock = new object();
private static DateTime LastImport = DateTime.MinValue;
public static ImportInfo Import()
{
lock (ImportLock)
{
if (DateTime.Now.AddSeconds(-10) < LastImport)
{
rules: {
"capitalized-comments": "off",
"multiline-comment-style": "off",
"no-console": "off",
"no-await-in-loop": "off",
"quote-props": "off",
"sort-keys": "off",
"arrow-parens": "off",
"no-tabs": "off",