Skip to content

Instantly share code, notes, and snippets.

@artygrand
artygrand / react.js
Created October 6, 2021 05:30
Wrap react's setState with callback or mutator
const wrappedSetInvoice = useCallback((value: ((i: InvoiceModel) => InvoiceModel) | InvoiceModel) => {
setInvoice(old => {
const updated = value instanceof Function ? value(old) : value;
return {...updated, dirty: true};
});
}, [setInvoice]);
@artygrand
artygrand / Dungeon.cs
Created September 18, 2019 08:43
Wrong dungeon generator
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class Dungeon : MonoBehaviour
{
public static float[] MapSize;
[Header("World Generation Values")]
@media (min-width:1200px){
.auto-clear .col-lg-1:nth-child(12n+1){clear:left;}
.auto-clear .col-lg-2:nth-child(6n+1){clear:left;}
.auto-clear .col-lg-3:nth-child(4n+1){clear:left;}
.auto-clear .col-lg-4:nth-child(3n+1){clear:left;}
.auto-clear .col-lg-6:nth-child(odd){clear:left;}
}
@media (min-width:992px) and (max-width:1199px){
.auto-clear .col-md-1:nth-child(12n+1){clear:left;}
.auto-clear .col-md-2:nth-child(6n+1){clear:left;}
SELECT entry.id as entry_id,
v_brand.value as brand,
v_year.value as year
FROM entity
JOIN entry
ON entity.id = entry.entity_id
JOIN value v_brand
ON v_brand.parameter_id = 1
AND v_brand.entry_id = entry.id
JOIN value v_year
@artygrand
artygrand / script.js
Created September 14, 2017 05:40
action on hovered text
var getSelectedText = function() {
var text = '';
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection) {
text = document.selection.createRange().text;
}
return text;
};
@artygrand
artygrand / 1Repository.php
Last active May 29, 2017 10:51
Repo - entity - fields
<?php
namespace Module\Entity\Models;
use Sydes\Database;
use Sydes\PDO;
class Repository
{
/** @var PDO */
protected $db;
@artygrand
artygrand / load.php
Created March 22, 2017 07:50
Curl file loader
<?php
set_time_limit(0);
$file = dirname(__FILE__) . '/file.tgz';
$url = 'http://site/file.tgz';
$file_offset=filesize($file);
$file_offset=$file_offset-1024*4;
@artygrand
artygrand / index.html
Created February 28, 2017 08:17
old JS maze generator
<HEAD><script>
<!-- Original: Darren Latham -->
<!-- Begin
function buildMaze(width, height) {
document.write("<html><style type=\"text/css\">.b { background:black;color:black} ");
document.write(".w { color:white;background:white }</style><body>");
var error = 0;
if ( (parseInt(width) < 5) || (parseInt(height) > 20) ) {
document.write("<p>The width entered ("+width+") must be between 5 and 20. Hit back to try again.</p>");
@artygrand
artygrand / index.html
Created February 28, 2017 08:15
old JS landscape generatror
<HEAD><SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var WIDTH = 1;
var XA = 0;
var XB = 64;
var YA = 0;
var YB = 64;
var Z1 = 0;
var Z2 = 0;
@artygrand
artygrand / decoder.php
Last active February 24, 2017 10:37
Sample XOR encoder
<?php
$encoded = "..."; // <-- encoded string from the request
$decoded = "";
for( $i = 0; $i < strlen($encoded); $i++ ) {
$b = ord($encoded[$i]);
$a = $b ^ 123; // <-- must be same number used to encode the character
$decoded .= chr($a)
}