Skip to content

Instantly share code, notes, and snippets.

View Alina-chan's full-sized avatar

Alina Balaur Alina-chan

View GitHub Profile
@Alina-chan
Alina-chan / longest_value.php
Created April 18, 2018 11:08
Quick function to find the longest value out of an array - returns position, value and length of the longest value
<?php
# Takes an array as input
# Returns an array with the length, position and string of the longest value
function arrayLongestValue( $tmp = array() ) {
if( !empty($tmp) ){
$lengths = array_map('strlen', $tmp);
$max_length = max($lengths);
@Alina-chan
Alina-chan / validurl.js
Created January 13, 2021 13:20
Javascript URL Validator
function validURL(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
return !!pattern.test(str);
}
@Alina-chan
Alina-chan / remove-comments.bash
Created February 18, 2021 13:26
Remove comments from file
sudo sed -i 's/^\#.*$//g' PATH/FILE.EXTENSION && sudo sed -i '/^$/d' PATH/FILE.EXTENSION
@Alina-chan
Alina-chan / publish.sh
Created September 29, 2023 11:58
How to read multiple Publisher objects from publish response and write PUBLISHER_N in .env file
# Get a space-separated string of publisher object IDs
PUBLISHER_IDS_STRING=$(echo "$newObjs" | jq -r 'select(.objectType | contains("::Publisher")).objectId')
# Read the Publishers string into an array using a while loop
declare -a PUBLISHERS
while IFS= read -r line; do
PUBLISHERS+=("$line")
done <<< "$PUBLISHER_IDS_STRING"
# Create a temporary file to hold the environment variables
@Alina-chan
Alina-chan / useGetObjects.ts
Created October 20, 2023 16:18
A hook in React that returns owned objects by given type.
import { JsonRpcProvider } from "@mysten/sui.js";
export function useGetObjects(provider: JsonRpcProvider) {
const getObjectsByType = (
address: string | undefined,
type: string,
nextCursor: string = ''
): Promise<any> => {
// return an empty array for non-address.
@Alina-chan
Alina-chan / getDynamicFieldsDataForTable.ts
Last active April 11, 2024 12:47
How to get Table dynamic fields of an object
// Retrieve the whitelist object by ID
const whitelist = await client.getObject({
id: "0x2cf9813bc67835218b09e0444b452cedb0aec96cc82283bdbac30e055dc76e82",
options: { showContent: true },
});
// Here is the content object from the query response
const whitelistContent: any = whitelist.data?.content;
// Check if there are entries in your table by its size