Skip to content

Instantly share code, notes, and snippets.

Avatar
🙌
Catching up with 3 months of notifications

Rahul Kadyan znck

🙌
Catching up with 3 months of notifications
View GitHub Profile
@znck
znck / Example.vue
Created Jan 1, 2021
Preview API Example
View Example.vue
<preview>
<setup
:requests="{
// Mock requests
'/api/repos': $p.repeat(10, id => ({ id })),
'/api/repos/:id': id => $p.x.getUser(id),
'/api/repos/znck0': $p.http.status(404),
}"
:components="{
@znck
znck / reactivity.js
Created Oct 14, 2020
A simple re-implementation of Vue's reactivity system
View reactivity.js
/** @type {WeakMap<object, Map<any, Set<Function>>>} */
const targetMap = new WeakMap()
let activeEffect = undefined
let shouldTrack = true
const effectStack = []
const trackStack = []
/**
* @param {object} target
@znck
znck / format.swift
Last active Sep 8, 2020
Format VS Code copied code snippet
View format.swift
import Cocoa
let pasteboard = NSPasteboard.general
let re1 = try! NSRegularExpression(pattern: "background-color:.*?;")
let re2 = try! NSRegularExpression(pattern: "font-size:.*?;")
let re3 = try! NSRegularExpression(pattern: "font-family:.*?;")
let htmlType = NSPasteboard.PasteboardType(rawValue: "public.html")
@znck
znck / shimmer.css
Last active Aug 13, 2020
CSS only shimmer
View shimmer.css
@keyframes placeHolderShimmer {
0% {
background-position: -80px 0;
}
100% {
background-position: 640px 0;
}
}
@znck
znck / array.ts
Created Jan 27, 2020
Array.prototype.forEachNonBlocking
View array.ts
export async function forEachNonBlocking<T>(
arrayOrIterator: IterableIterator<T> | T[],
fn: (item: T) => void,
frameBudgetInMillis: number = 10
): Promise<void> {
const iterator = Array.isArray(arrayOrIterator)
? arrayOrIterator[Symbol.iterator]()
: arrayOrIterator;
return new Promise((resolve, reject) => {
@znck
znck / promised.ts
Last active Aug 14, 2019
Moved to https://github.com/znck/promised | A utility to convert callbacks to promises.
View promised.ts
import {promisify, CustomPromisify} from 'util'
export type FunctionProxy<T extends Function> = CustomPromisify<T>
export type PackageProxy<P extends { [key: string]: Function }> = {
[K in keyof P]: FunctionProxy<P[K]>
}
export function promised<T extends { [key: string]: Function | any }>(target: T): PackageProxy<T> {
@znck
znck / begin-again.md
Last active Jan 29, 2019
VueBLR - Begin Again Workshop
View begin-again.md

# Initial Commit

# Create new npm project

  • Create new project
    npm init
View w3c-html-validator.js
import { mount } from 'vue-test-utils'
import { createRenderer } from 'vue-server-renderer'
import MyComponent from './MyComponent.vue'
const renderer = createRenderer()
renderer.renderToString(
mount(MyComponent).vm,
(error, html) => {
@znck
znck / Hello.vue
Last active Oct 29, 2017
vue component compiler source map issue
View Hello.vue
<template>
<h2 class="red">{{msg}}</h2>
</template>
<script>
export default {
data () {
return {
msg: 'Hello from Component A!'
}
@znck
znck / index.html
Last active Jul 14, 2017
jquery demo: JS Bin// source https://jsbin.com/meximo
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.group {
display: block;
margin: 0 15px 15px;