Skip to content

Instantly share code, notes, and snippets.

View multivoltage's full-sized avatar

Diego Tonini multivoltage

View GitHub Profile
@multivoltage
multivoltage / HeaderFooterRecyclerViewAdapter.java
Created April 14, 2016 10:41 — forked from mheras/HeaderFooterRecyclerViewAdapter.java
Header & footer support for RecyclerView.Adapter
public abstract class HeaderFooterRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_MAX_COUNT = 1000;
private static final int HEADER_VIEW_TYPE_OFFSET = 0;
private static final int FOOTER_VIEW_TYPE_OFFSET = HEADER_VIEW_TYPE_OFFSET + VIEW_TYPE_MAX_COUNT;
private static final int CONTENT_VIEW_TYPE_OFFSET = FOOTER_VIEW_TYPE_OFFSET + VIEW_TYPE_MAX_COUNT;
private int headerItemCount;
private int contentItemCount;
private int footerItemCount;
@multivoltage
multivoltage / beautifulSort.js
Created March 3, 2020 15:20
a sort function bases on most used entries
const MOST_USED = ["BASE", "INTERMEDI", "REJECTED", "FULL"] // ["BASE", "INTERMEDI", "REJECTED", "FULL"];
const list = ["super","base wire","base","START","PREMIUM","PLUS","Intermedi","Blocked","Advanced"] // ["REJECTED",",ciccio","FULL","INTERMEDI","BASE"]
function beautifulSort(a,b){
const i1 = MOST_USED.indexOf(a.toUpperCase())
const i2 = MOST_USED.indexOf(b.toUpperCase())
if(MOST_USED.includes(a.toUpperCase()) && MOST_USED.includes(b.toUpperCase)){
return i1-i2
}
@multivoltage
multivoltage / example_context_api_ts.tsx
Created April 12, 2020 10:38
Simple usage for context api with value and set value written in TS
export interface I_AttachmentsContext {
urls: string[];
setUrls: (values: string[]) => void;
}
const AttachmentsContext = React.createContext<I_AttachmentsContext>({
urls: [],
setUrls: (values: string[]) => {
//
}
@multivoltage
multivoltage / remapObject.js
Created May 21, 2020 19:52
Take any object (null,undefined string boolean object array...) and return same object with some new values based on some rules
// my backend return all date in a UTC format without "Z" at the end of string. I want to add a "Z" for all data that contain a date
// from "2020-05-21T19:51:25.396" to "2020-05-21T19:51:25.396Z"
const object: any = {
name: "-",
created_at: "-",
created_when: "-",
calendar: {
updated_at: "-",
@multivoltage
multivoltage / customize materia ui
Created November 20, 2020 15:04
Example of a big configuration for theme and Textfield in material ui (react) - (font and colors)
```
const primaryColor = "#15C3B2";
const secondaryColor = "#227C9D";
const theme = createMuiTheme({
palette: {
primary: {
main: primaryColor, //"#49cbdc",
},
secondary: {
main: secondaryColor, // "#ff4081",
//
// Werewolf, it shall have 30 HP and 5 DMG
class Werewolf extends Enemy {
constructor(){
super('Werewolf', 30, 5);
}
}
// Vampire, it shall have 50 HP and 10 DMG
class Vampire extends Enemy {
constructor(){
@multivoltage
multivoltage / get-pub-key-eth.ts
Created March 7, 2024 09:46
simple code to get pubkey from 24 words in eth chain
const bip39 = require("bip39");
const hdkey = require("ethereumjs-wallet").hdkey;
async function find() {
const mnemonic = "word1 word2 ... word24"
const buf = await bip39.mnemonicToSeed(mnemonic);
const hdwallet = hdkey.fromMasterSeed(buf);
const path = "m/44'/60'/0'/0/0";
const wallet = hdwallet.derivePath(path).getWallet();
@multivoltage
multivoltage / example.ts
Last active October 4, 2024 12:51
helper function to send email with attachment using AWS ses
export class RawMessageDataBuilder {
private msg = "";
constructor({
to,
fullname,
email,
phone,
city,