Skip to content

Instantly share code, notes, and snippets.

View gryzzly's full-sized avatar

Misha Reyzlin gryzzly

View GitHub Profile
import { useEffect, useRef } from 'react';
type draw = (fraction: number) => void;
type duration = number;
const useAnimation = (duration: duration, draw: draw) => {
const updateDurationRef = useRef<null | ((newDuration: number) => void)>(null);
const currentAnimationIdRef = useRef(0);
const elapsedTimeRef = useRef(0);
@gryzzly
gryzzly / semver.js
Created April 14, 2023 09:20
Semver generated by chatGPT
// semver.js
function isValidSemVer(version) {
const semverRegex = /^(\d+)\.(\d+)\.(\d+)(?:-([\w\d]+(?:\.[\w\d]+)*))?(?:\+([\w\d]+(?:\.[\w\d]+)*))?$/;
if (!semverRegex.test(version)) {
return false;
}
return true;
@gryzzly
gryzzly / deno-watch-html-run-js.txt
Created April 6, 2023 20:13
deno run --watch ./html/index.html build.js produces an error attempting to execute html file
# this is a minimal reproducible example to illustrate how deno is attempting to execute
# an html file passed in as a value for --watch option
#
# tested with deno 1.24.3 and 1.32.1
% mkdir html
% touch html/index.html
% echo "<\!doctype html>" >> html/index.html
% touch build.js
% echo "console.log('build running');" >> build.js
@gryzzly
gryzzly / NotificationsModule.java
Created October 6, 2020 10:13
React Native Android JSON parameters for Intents
public class NotificationsModule extends ReactContextBaseJavaModule {
private static String channelID = "8888";
private static String channelTitle = "Notifications";
private ReactApplicationContext reactContext;
public static final String NAME = "Notifications";
NotificationsModule(ReactApplicationContext context) {
super(context);
reactContext = context;
@gryzzly
gryzzly / Notifications.java
Last active September 2, 2020 11:30
React Native Notifications.java, show a notification
package com.foo.bar;
import android.util.Log;
import android.content.Context;
import android.provider.Settings;
import java.lang.System;
import android.app.Notification;
import androidx.core.app.NotificationCompat;
@gryzzly
gryzzly / electron-3.0.2-facebook-login.js
Created October 5, 2018 13:34
Electron 3 + Facebook login with `webRequest.onBeforeRequest` instead of webContents `"did-get-redirect-request"`
ipcMain.on('facebook-sign-on', function onFacebookSignOn(
event,
repromptFacebook,
) {
const options = {
client_id: FACEBOOK_CLIENT_ID,
scope: 'public_profile,email',
redirect_uri: 'https://www.facebook.com/connect/login_success.html',
auth_type: repromptFacebook ? 'rerequest' : '',
source ~/.git-prompt.sh
#[18:39:16] ~/railscode/dostuff (dev)$
export PS1='\[$(tput setaf 4)\]┌\[$(tput sgr0)\] \[\033[0;36m\][\t]\[\033[0m\] \[\033[0;32m\]\w\[\033[0m\]\[\033[0;33m\]$(__git_ps1)\[\033[0m\]\n\[$(tput setaf 4)\]└\[$(tput sgr0)\] '
source ~/git-completion.bash
@gryzzly
gryzzly / getBoundingBox-center-distance.js
Created July 17, 2017 17:22
Get bbox from coordinates and distance
/**
* Get bounding box from set of coordinates [lat,lng] and distance in (deg) adopted to JS
*
* @param {number} distance - distance (deg) from the point represented by centerPoint
* @param {array} centerPoint - two-dimensional array containing center coords [latitude, longitude]
* @description
* Computes the bounding coordinates of all points on the surface of a sphere
* that has a great circle distance to the point represented by the centerPoint
* argument that is less or equal to the distance argument.
* Technique from: Jan Matuschek <http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates>
@gryzzly
gryzzly / HTMLWebpackPlugin-inline-source.js
Created February 17, 2016 17:04
A version of HTMLWebpackPlugin that can inline the assets sources
var minifyJS = require('uglify-js').minify;
var minifyHTML = require('html-minifier').minify;
// TODO: use lodash.template when Travis
// updates npm version to >= 3
var _ = require('lodash');
var path = require('path');
var fs = require('fs');
function toMinifiedSource(compilation, path) {
return minifyJS(
@gryzzly
gryzzly / index.js
Last active August 29, 2015 14:27
requirebin sketch
var createRedux = require('redux').createRedux;
var reducer = function (state, action) {
return state;
};
var redux = createRedux(reducer);
redux.dispatch({
type: 'FOO',
payload: {}
});