Skip to content

Instantly share code, notes, and snippets.

View vojty's full-sized avatar
🦦

Tomáš Vojtášek vojty

🦦
View GitHub Profile
SunCalc = (function() {
var J1970 = 2440588,
J2000 = 2451545,
deg2rad = Math.PI / 180,
M0 = 357.5291 * deg2rad,
M1 = 0.98560028 * deg2rad,
J0 = 0.0009,
J1 = 0.0053,
J2 = -0.0069,
C1 = 1.9148 * deg2rad,
@vojty
vojty / prettier_format.ts
Created November 26, 2021 07:04
Prettier node usage
import prettierConfig from './.prettierrc'
const code = 'const foo = 1; const bar = 2;'
const out = prettier.format(code, {
...prettierConfig,
parser: 'typescript'
})
console.log(out)
@vojty
vojty / dirname.mjs
Created October 25, 2021 10:50
__dirname with ESM modules
import path from 'path'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
@vojty
vojty / readme.md
Created October 1, 2021 07:02
Route specific domain via custom DNS server
@vojty
vojty / osxvpnrouting.markdown
Created July 9, 2021 08:55 — forked from taldanzig/osxvpnrouting.markdown
Routing tips for VPNs on OS X

Routing tips for VPNs on OS X

When VPNs Just Work™, they're a fantastic way of allowing access to a private network from remote locations. When they don't work it can be an experience in frustration. I've had situations where I can connect to a VPN from my Mac, but various networking situations cause routing conflicts. Here are a couple of cases and how I've been able to get around them.

Specific cases

Case 1: conflicting additional routes.

In this example the VPN we are connecting to has a subnet that does not conflict with our local IP, but has additional routes that conflict in some way with our local network's routing. In my example the remote subnet is 10.0.x.0/24, my local subnet is 10.0.y.0/24, and the conflicting route is 10.0.0.0/8. Without the later route, I can't access all hosts on the VPN without manually adding the route after connecting to the VPN:

@vojty
vojty / MarkdownPage.tsx
Created February 18, 2021 11:40 — forked from jaredpalmer/MarkdownPage.tsx
Get headers from MDX in Next.js
import {MDXProvider} from '@mdx-js/react';
import {MDXComponents} from 'components/MDX/MDXComponents';
import {Toc} from 'components/Toc/Toc';
import * as React from 'react';
export interface MarkdownProps<Frontmatter> {
meta: Frontmatter;
children?: React.ReactNode;
}
@vojty
vojty / gist:284600631dcdb6e57de3f54a22e911e2
Created December 21, 2017 15:45
Enzyme 3.2 + React-portal
const portalComponent = wrapper.find(Portal).at(0);
const portalInstance = portalComponent.instance();
const portalWrapper = new ReactWrapper(portalInstance.props.children);
portalWrapper.find(...)
@vojty
vojty / jest.md
Last active January 25, 2018 11:05
Jest cheat sheet

Jest cheat shiiiit

Expect

expect.any(constructor) // expect(callback).toBe(expect.any(Function))
expect.assertions(number) // total count of expected assertions, useful for async tests
.not
.resolves
.rejects
.toBe(value)

.toHaveBeenCalled()

@vojty
vojty / branfuck.js
Created November 12, 2016 18:11
Brainfuck.js
function branfuck(code, input){
const output = [];
const data = [];
let dataPointer = 0;
let inputPointer = 0;
let inputArr = input.split('').map(i => i.codePointAt(0))
const chars = code.split('');
let codePointer = 0;
@vojty
vojty / multiply.js
Created November 6, 2016 14:51
Large numbers multiplication
function mul(num1, num2) {
// Convert to array of string in reverse order (right to left calc)
num1 = `${num1}`.split('').reverse();
num2 = `${num2}`.split('').reverse();
// Init empty array
const d = [];
for(let i = 0; i < num1.length + num2.length; i++) {
d[i] = 0;