Skip to content

Instantly share code, notes, and snippets.

View MicrowaveDev's full-sized avatar

Microwave Dev MicrowaveDev

View GitHub Profile
@MicrowaveDev
MicrowaveDev / ImageToInstagramController.php
Last active January 6, 2023 19:09
Laravel Intervention Image place to square for instagram(fill background, vertical or horizontal align a image) plus blur option.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function imageFillToSquare(Request $request){
@MicrowaveDev
MicrowaveDev / messagesFuncs.js
Last active December 5, 2022 19:04
Save last telegram messages and autodelete last messages by theme name
const lsMessages = {
};
function pleaseRegister(msg) {
return sendMessageAndClear('register', msg, bot.sendMessage(msg.chat.id, `Please register in bot`, {parse_mode: 'HTML'}));
}
function alreadyRegistered(msg) {
return sendMessageAndClear('register', msg, bot.sendMessage(msg.chat.id, `You already registered`, {parse_mode: 'HTML'}));
@MicrowaveDev
MicrowaveDev / PolygonCheckerV1.sol
Last active August 3, 2020 16:21
How to optimize ETH smart contract size
contract PolygonChecker {
struct PolygonData {
int256[2][] points;
}
mapping(uint256 => PolygonData) polygons;
function addPolygonPoint(uint256 polygonId, int256[2] memory point) public {
polygons[polygonId].points.push(point);
}
library PolygonUtils {
struct PolygonData {
int256[2][] points;
}
function isInsidePolygon(PolygonData storage _polygon, int256[2] memory _point) public view returns (bool) {
bool inside = false;
uint256 j = _polygon.points.length - 1;
@MicrowaveDev
MicrowaveDev / PolygonCheckerV2.sol
Created August 3, 2020 16:17
PolygonCheckerV2
import "./PolygonUtils.sol";
contract PolygonChecker {
mapping(uint256 => PolygonUtils.PolygonData) polygons;
function addPolygonPoint(uint256 polygonId, int256[2] memory point) public {
polygons[polygonId].points.push(point);
}
function isInsidePolygonById(int256[2] memory _point, uint256 _polygonId) public view returns (bool) {
@MicrowaveDev
MicrowaveDev / logContractSizes.js
Created August 3, 2020 15:58
Get all compiled smart contracts sizes
const fs = require('fs');
const Table = require('cli-table');
const table = new Table({
head: ['Contract', 'Size (bytes)'],
colWidths: [50, 15]
});
const testFolder = './build/contracts/';
@MicrowaveDev
MicrowaveDev / Erc721Factory.sol
Last active May 31, 2020 15:05
Erc721 Factory by OpenZeppelin
// File: @openzeppelin/contracts/GSN/Context.sol
pragma solidity ^0.5.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
@MicrowaveDev
MicrowaveDev / gist:ec5835c07aac6d4fd95a754959d5ab16
Last active March 5, 2020 20:56
Mysql to Postgres migration
```
createdb my_database
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
sudo apt install pgloader
mysql -uroot -proot -e "SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"
pgloader --with "quote identifiers" mysql://root:root@localhost/my_database postgresql:///my_database
```
@MicrowaveDev
MicrowaveDev / .block
Created December 17, 2019 21:26
fresh block
license: mit
pragma solidity ^0.5.2;
/**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/
library Roles {
struct Role {
mapping (address => bool) bearer;
}