Skip to content

Instantly share code, notes, and snippets.

View vkbansal's full-sized avatar
💭
I may be slow to respond.

Vivek Kumar Bansal vkbansal

💭
I may be slow to respond.
View GitHub Profile
@vkbansal
vkbansal / README.md
Last active August 29, 2015 14:06 — forked from mbostock/.block
Responsive D3 chart

Chord diagrams show directed relationships among a group of entities. This example also demonstrates simple interactivity by using mouseover filtering. Layout inspired by Martin Krzywinski's beautiful work on Circos.

// run this before
// npm run eslint > lint.log
const fs = require('fs');
let data = fs.readFileSync('./lint.log', 'utf8');
let output = {};
for (let line of data.split('\n')) {
@vkbansal
vkbansal / .gitignore
Last active April 17, 2019 14:45
Printing TypeScript code from AST
node_modules
@vkbansal
vkbansal / snippets.sh
Last active September 18, 2019 13:53
[Bash Snippets] Quick & dirty bash snippets #bash #snippets
# remove all the git branches with update in it
git rmf $(git ls | grep update | tr '\n' ' ')
# get version from package.json. may not work with 1.0.0-alpha.1
PKG_VERSION=$(node -e "console.log(require('./package.json').version);")
MAJOR_VERSION="$(echo $PKG_VERSION | cut -d "." -f 1)"
MINOR_VERSION="$(echo $PKG_VERSION | cut -d "." -f 2)"
PATCH_VERSION="$(echo $PKG_VERSION | cut -d "." -f 3)"
# vscode tab issue fix
@vkbansal
vkbansal / transform.ts
Created September 23, 2019 16:50
[TS tranformer] TS tranformer for codemod #typescript #codemod #ast
function transformer<T extends ts.Node>(): ts.TransformerFactory<T> {
return context => {
const visit: ts.Visitor = node => {
switch (node.kind) {
case ts.SyntaxKind.Parameter:
if (!(node as any).type) {
const newNode = ts.createParameter(
(node as ts.ParameterDeclaration).decorators,
(node as ts.ParameterDeclaration).modifiers,
(node as ts.ParameterDeclaration).dotDotDotToken,
@vkbansal
vkbansal / strings.d.ts
Created January 11, 2022 09:38
strings-ext-02
// strings.yaml.d.ts
declare const strings: Record<string, string>;
export default strings;
@vkbansal
vkbansal / strings.yaml
Created January 11, 2022 09:40
string-ext-03
homePageTitle: Home
aboutPageTitle: About
homePageContent:
para1: |
Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquam, eos
animi. Corporis harum quaerat dicta possimus illum aut unde laborum
excepturi suscipit quibusdam perspiciatis dolorum alias, exercitationem
similique illo? Distinctio.
para2: |
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit
@vkbansal
vkbansal / vit-config.js.diff
Created January 11, 2022 09:41
string-ext-04
// vite.config.js
+import yaml from "@rollup/plugin-yaml";
+
/**
* @type {import('vite').UserConfig}
*/
const config = {
root: "./src",
+ plugins: [yaml()],
};
@vkbansal
vkbansal / StringsContext.tsx
Last active January 11, 2022 09:46
string-ext-06
// StringsContext.tsx
export function useStringsContext(): Record<string, any> {
return React.useContext(StringsContext);
}
export interface UseLocaleStringsReturn {
getString(key: string): string;
}
export function useLocaleStrings() {