Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hdf
hdf / sunrise.cpp
Last active April 12, 2020 22:02
Sunrise calculation
/* source: http://aa.quae.nl/en/reken/zonpositie.html */
// source: http://en.wikipedia.org/wiki/Julian_day
int julian_jdn(int year, int month, int day) { // convert Gregorian calendar date to Julian Day Number
int a = (14 - month) / 12;
int y = year + 4800 - a;
int m = month + 12 * a - 3;
return day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;
}
@hdf
hdf / dir.py
Last active July 22, 2020 16:53
Generate html file with foldable recursive directory listing. (For directories with no auto indexing.)
import os, sys
from datetime import datetime
from zipfile import ZipFile
dir = '.'
out = 'dir.html'
if len(sys.argv) > 1:
dir = sys.argv[1]
if len(sys.argv) > 2:
@hdf
hdf / fourier.js
Last active March 12, 2020 11:37
Discrete Fourier transformation
// Coding Challenge 130.3: Drawing with Fourier Transform and Epicycles
// Daniel Shiffman
// https://thecodingtrain.com/CodingChallenges/130.1-fourier-transform-drawing.html
// https://thecodingtrain.com/CodingChallenges/130.2-fourier-transform-drawing.html
// https://thecodingtrain.com/CodingChallenges/130.3-fourier-transform-drawing.html
// https://youtu.be/7_vKzcgpfvU
// https://editor.p5js.org/codingtrain/sketches/ldBlISrsQ
class Complex {
constructor(a, b) {
@hdf
hdf / animate.py
Last active September 6, 2022 23:18
Comb particle evolution data from multiple files into one moment to moment, system state based file. Also visualize the data using matplotlib.
# From: https://gist.github.com/hdf/42f0895a091b4a6a6d5d9eeb5cca8edf
import time, sys, os#, arrow
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.colors as colors
import matplotlib.ticker as ticker
import json
@hdf
hdf / BigO.js
Created December 23, 2018 14:59
Based on the array in question, and the counter value (you have to put the code for that in the function in question yourself), this function will tell us the time complexity of the function.
function BigO(arr, arr3) { // Second array is optional
this.accumulator = 0; // Can be set here, or when calling ClosestMatch
/* function factorial(n, i) {
if (n > 171) // Overflow prevention
return Infinity;
if (typeof i == 'undefined')
i = 1;
if (n < i)
return 1;
if (n === i)
@hdf
hdf / index.html
Last active November 29, 2018 16:56
Google Drive Demo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Google Drive Demo</title>
</head>
<body>
<div style="position: absolute; top: 40%; left: 50%; transform: translate(-50%, -40%); text-align: center;">
<a href="https://drive.google.com/open?id=1v1-ApluL9dCGx4znKVSXGKnBf4dFVGuv">Letöltés</a><br><br>
@hdf
hdf / NthClosest.js
Last active December 22, 2018 20:41
Interview stuff?
// Inspired by:
// https://interviewing.io/recordings/Go-Microsoft-1
function NthClosest(points, match, n) {
if (n < 1 || n > points.length || points[0].length != match.length)
return false;
function distance(p1, p2) { // Works in any dimensions.
let out = 0, d = 0, len = p1.length;
for (let i3 = 0; i3 < len; i3++) {
@hdf
hdf / programozz.txt
Last active September 19, 2018 13:45
Előadás terv javaslat
Mi a programozás?
Megmondani a gépnek hogy mit csináljon. Nagyon szájbarágósan. (Angol tudás elengedhetetlen.)
Számomra a programozás olyan mint a legózás, csak olcsóbb, nem megy tönkre a kezed tőle és sose fogysz ki a darabokból.
Engem azért vonzott a programozás, mert olyan volt mint a varázslás. Mintha pár varázs szó beírásával életet lehelnél az élettelenbe. Viselkedést adhatsz egy tárgynak. És érdekelt, hogy a játékok, meg egyéb programok, amiket használtam hogyan működnek. Illetve az automatizáció is mindig vonzott, mert olyan mint a csalás. Ráveszed a világot, hogy dolgozzon helyetted.
Mihez van szükség hozzá?
Kell egy feladat.
A feladat határozza meg, hogy melyik a megfelelő eszköz (program nyelv) hozzá.
Számítógép internet eléréssel, Google, program nyelv dokumentáció/referencia, fejlesztői környezet: Visual Studio (Code) / Notepad++, idő, érdeklődés.
@hdf
hdf / bubbleSort.js
Last active December 22, 2018 17:18
function bubbleSort(arr, cmp) {
var len = arr.length, tmp, n;
if (typeof cmp !== 'function')
cmp = function(a, b) {
return a > b;
};
do {
n = 0;
for (var i = 1; i < len; i++) {
if (cmp(arr[i], arr[i-1])) continue;
This file has been truncated, but you can view the full file.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>vis.js Plot</title>
<style>
body {font: 10pt arial;}
#mygraph>div {border: 1px solid black;}
#mygraph,#controlls {display: inline-block; vertical-align: top;}
</style>