Skip to content

Instantly share code, notes, and snippets.

View particle4dev's full-sized avatar
👨‍💻
Building

Nam Hoang particle4dev

👨‍💻
Building
View GitHub Profile
@particle4dev
particle4dev / main.rs
Created November 28, 2021 10:24 — forked from FrankC01/main.rs
Faux example of serializing BTreeMap to Solana State
use std::{collections::BTreeMap, iter::repeat};
use arrayref::{array_mut_ref, array_ref, array_refs, mut_array_refs};
use borsh::{BorshDeserialize, BorshSerialize};
const INITIALIZED_BYTES: usize = 1;
const TRACKING_CHUNK_LENGTH: usize = 4;
const TRACKING_CHUNK_BYTES: usize = 5116;
const TRACKING_ACCOUNT_STATE_SPACE: usize =
INITIALIZED_BYTES + TRACKING_CHUNK_LENGTH + TRACKING_CHUNK_BYTES;
function removeDuplicates(nums: number[]): number {
const list = {};
let total = 0;
for(let i = 0; i < nums.length; i += 1) {
if(!list[nums[i]]) {
list[nums[i]] = true;
total += 1;
} else {
nums.splice(i, 1);
i -= 1;
@particle4dev
particle4dev / AndroidManifest.xml
Created June 29, 2020 07:18 — forked from Venryx/AndroidManifest.xml
Record audio on Android in the background (even when screen is off)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp">
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
<service android:name=".ForegroundService" android:enabled="true" android:exported="true"></service>
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
@particle4dev
particle4dev / axios-catch-error.js
Created April 3, 2020 15:00 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@particle4dev
particle4dev / RNG.sol
Created September 12, 2019 10:24 — forked from Bunjin/RNG.sol
Blockhash RNG immune to tampering for PoS and PoW
contract RNG {
bytes32 encrypted_seed;
bytes32 revealed_seed;
bytes32 revealed_secret;
uint odds;
uint bet_blocknumber;
uint bet_input;
bool bet_made;
uint bet_result;
string log;
@particle4dev
particle4dev / slugify.js
Created June 11, 2019 07:20 — forked from hagemann/slugify.js
Slugify makes a string URI-friendly
function slugify(string) {
const a = 'àáäâãåăæçèéëêǵḧìíïîḿńǹñòóöôœøṕŕßśșțùúüûǘẃẍÿź·/_,:;'
const b = 'aaaaaaaaceeeeghiiiimnnnooooooprssstuuuuuwxyz------'
const p = new RegExp(a.split('').join('|'), 'g')
return string.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
{
"result": {
"error_events": ["StartFailed", "NegotiateFailed", "TakerFeeValidateFailed", "MakerPaymentTransactionFailed", "MakerPaymentDataSendFailed", "TakerPaymentValidateFailed", "TakerPaymentSpendFailed", "MakerPaymentRefunded", "MakerPaymentRefundFailed"],
"events": [{
"event": {
"data": {
"lock_duration": 7800,
"maker_amount": "1",
"maker_coin": "LABS",
"maker_payment_confirmations": 1,
{
"coin": "BEER",
"method": "send_raw_transaction",
"queueid": 0,
"tx_hex": "0400008085202f890396401873fc1af4f849125c1fdf0f53b75799f644cc01e0e491830711cfd0e6bd000000006a47304402204cfd3ce79ccc98062425b2e71e224357d29c43c08e8287422b0009f60af1a76a02204bba67f671afffa4c23e1178922f413805386bd2e271799dd96858c82b1812820121027932139a858bb9c65eafdc74fa0798617efc18b81c0c5946c798c7a5a6b95d08ffffffffd7dbbb6c7d21cc6a69fe862b32f7c445b65e0204f254d6b17b92a3b56763ffad000000006b4830450221008f98951c106a8a0ea7e9e532897aba963baff2141d924853d72fa974b018e49b022070cd2d6229387d2513afbceabcc6c8de48a65c3c57cf4dd685d2c53359692ef80121027932139a858bb9c65eafdc74fa0798617efc18b81c0c5946c798c7a5a6b95d08ffffffff004e8684090f246b5bee7cc99b824904c36ea3aa9bcb190f1658b1f0e7c5ad3f000000006a473044022032ed534e1864a058247e1072900a66a998f5a8d0d1434b050af5032ae7aaf1280220618a0537d2e19e061d29725a7730a9aa3af695371bc5da5f62aac1d80babe68b0121027932139a858bb9c65eafdc74fa0798617efc18b81c0c5946c798c7a5a6b95d08ffffffff0297bfc901000000001976a914b1cc1a6fe678e98fda
@particle4dev
particle4dev / API.md
Created September 17, 2018 12:00 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@particle4dev
particle4dev / index.md
Created September 11, 2018 04:48 — forked from bvaughn/index.md
Interaction tracking with React

Interaction tracking with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracking these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracking by way of a new NPM package, schedule. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.

This Gist provides some high-level docu