Skip to content

Instantly share code, notes, and snippets.

@ikawka
ikawka / nearby-coordinates.sql
Created October 9, 2022 03:17 — forked from statickidz/nearby-coordinates.sql
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC
@ikawka
ikawka / js-script.js
Created August 2, 2022 12:30
Handle string with with octal escape sequences
const hexToAscii = str => {
return str
.match(/.{2}/g)
.reduce(
(current, substr) => current + String.fromCharCode(parseInt(substr, 16)),
'',
)
.replaceAll(/\x00|\\b|\n|\r/g, ''); // remove unwanted characters
};
FROM php:7.2-fpm-alpine
# docker-entrypoint.sh dependencies
RUN apk add --no-cache \
# in theory, docker-entrypoint.sh is POSIX-compliant, but priority is a working, consistent image
bash \
# BusyBox sed is not sufficient for some of our sed expressions
sed
# install the PHP extensions we need
@ikawka
ikawka / git_plugin.md
Created December 14, 2021 07:54 — forked from ryanlindsey/git_plugin.md
Git plugin shortcuts for Oh My ZSH
Alias Command
g git
ga git add
gaa git add --all
gapa git add --patch
gb git branch
@ikawka
ikawka / IP Camera to Youtube via ffmpeg
Last active July 24, 2020 04:48
Stream from IP Camera to Youtube
ffmpeg \
-f lavfi \
-i anullsrc \
-rtsp_transport tcp \
-i $INPUT \
-tune zerolatency \
-vcodec libx264 \
-t 12:00:00 \
-pix_fmt + \
-c:v copy \
@ikawka
ikawka / createStore.tsx
Last active April 29, 2020 07:57
Global Store with React Context
/*
===== store.js =====
import createStore from '@store'
const initialState = { foo: 'bar' }
export const { Provider, connect } = createStore(initialState)
===== parent.js =====
import {Provider} from './store'
const Parent = () => {
return (
@ikawka
ikawka / fix-gyp-xcode-issue.txt
Last active March 31, 2020 05:36
Fix gyp issue; No Xcode or CLT version detected!
# get XCode Commandline path
xcode-select --print-path
# usually will output /Library/Developer/CommandLineTools
sudo rm -rf (what ever the output of above)
#install it back
xcode-select --install
@ikawka
ikawka / ImageUploader.jsx
Last active May 14, 2019 06:19
React image uploader that allows to drag your image to position and clip it. Returns base64 string of the image via callback function.
/*
How to use:
<ImageInput
width={200} // required, width of the image component
height={200} // required, height of the image compoent
image='' // initial image value
onUpdate={(image) => { console.log(image) } } // do something the the image string in base64
onUpdating={() => { console.log('component is currently being updated') }}
onUpdated={() => { console.log('component is currently has been updated') }} />
*/
@ikawka
ikawka / css
Created March 22, 2019 07:40
CSS Data Tree
/* Source: https://codepen.io/mckenziedave/ */
* {margin: 0; padding: 0;font-size: 16px!important;}
.tree ul {
padding-top: 20px; position: relative;
transition: all 0.5s;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
}
/*
* http://www.javascriptkit.com/dhtmltutors/sticky-hover-issue-solutions.shtml
* Method 3- Using CSS Media Queries Level 4 Interaction Media Features
*/
@media (hover:none),
(hover:on-demand) {
nav a:hover {
/* suppress hover effect on devices that don't support hover fully */
background: none;