Skip to content

Instantly share code, notes, and snippets.

View mupkoo's full-sized avatar

Mirko Akov mupkoo

View GitHub Profile
@mupkoo
mupkoo / SocketContextWithRef.ts
Created April 21, 2020 20:26
Using React Hooks for Phoenix Socket/Channels
import React, { createContext, useContext, useRef } from 'react';
import { Socket } from 'phoenix';
import AuthContext from './AuthContext';
const SocketContext = createContext<Socket>({} as Socket);
const SocketConsumer = SocketContext.Consumer;
const SocketProvider: React.FC = ({ children }) => {
let token = useContext(AuthContext).token!;
let socketRef = useRef<{
@mupkoo
mupkoo / class-decorator-test.js
Created May 23, 2023 17:47
Ember.JS add dynamic properties to a native class
/* eslint-disable ember/no-computed-properties-in-native-classes */
import { render, settled } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { module, test } from 'qunit';
import { set, defineProperty, computed } from '@ember/object';
function example(target) {
defineProperty(
target.prototype,
@mupkoo
mupkoo / number_to_words.php
Created April 7, 2017 08:02
PHP script to convert numbers to words in Bulgarian
<?php
// Taken from the internet
// Slighly modified
function _n($single, $plural, $number) {
if ((int) $number == 1) {
return $single;
} else {
return $plural;
}
}
@mupkoo
mupkoo / mysql.fish
Last active October 24, 2022 09:26
PostgreSQL and MySQL - Dump all databases into separate files
for db in (mysql -u root -e "SHOW DATABASES WHERE `Database` NOT LIKE '%test%'" -s --skip-column-names);
mysqldump -u root --single-transaction (string trim $db) > (string trim $db).dump;
end
@mupkoo
mupkoo / useAsyncEffect.ts
Created June 23, 2022 13:13
useAsyncEffect
import React, { useEffect, useState } from "react";
export default function App() {
const [count, setCount] = useState(1);
const [autoCount, setAutoCount] = useState(1);
useAsyncEffect(
function* () {
while (true) {
yield new Promise((resolve) => setTimeout(resolve, 1000));
@mupkoo
mupkoo / stripExifFromJPEGs.ts
Created May 14, 2022 12:22
Strip EXIF data from JPEGs
/**
* Strip EXIF data from JPEGs
*
* @param {File} file
*/
const stripExifFromJPEGs = (file: File): Promise<File | Blob> => {
// We want to strip the EXIF data only from JPEGs
if (file.type !== 'image/jpeg') {
return Promise.resolve(file)
}
@mupkoo
mupkoo / install-ruby-2.6.6.fish
Last active January 14, 2022 06:46
M1 Pro problems and how to fix them
# Use the following command to install Ruby 2.6.6
# The other 2.6 version might need this as well
set -gx optflags "-Wno-error=implicit-function-declaration"
set -gx LDFLAGS "-L/opt/homebrew/opt/libffi/lib"
set -gx CPPFLAGS "-I/opt/homebrew/opt/libffi/include"
set -gx PKG_CONFIG_PATH "/opt/homebrew/opt/libffi/lib/pkgconfig"
asdf install ruby 2.6.6
gem install mysql2 -v '0.5.3' -- --with-cflags=\"-I/usr/local/opt/openssl/include\" --with-ldflags=\"-L/usr/local/opt/openssl/lib\"
@mupkoo
mupkoo / script.sh
Last active November 17, 2019 11:52
How much space does your node_modules take up
$ cd documents
$ find . -name "node_modules" -type d -prune -print | xargs du -chs
--- Example output ---
1.0G ./Github/big-project/node_modules
225M ./Github/Trilon.io/node_modules
482M ./Github/Some_Demo/node_modules
1.7G total
@mupkoo
mupkoo / jsconfig.json
Last active August 13, 2019 20:33
jsconfig.json for Ember CLI project
{
"compilerOptions": {
"target": "es2018",
"experimentalDecorators": true,
"baseUrl": ".",
"paths": {
"{put-your-app-name-here}/tests/*": ["./tests/*"],
"{put-your-app-name-here}/mirage/*": ["./mirage/*"],
"{put-your-app-name-here}/*": ["./app/*"]
}