Skip to content

Instantly share code, notes, and snippets.

View irzhywau's full-sized avatar

Irzhy Ranaivoarivony irzhywau

View GitHub Profile
@irzhywau
irzhywau / sql-inner
Last active December 26, 2018 07:25
SQL 2 Tables
# ohatra
# table_1 (id, field_11, field_12)
# table_2 (id, field_21, field_22)
# de field_11 <-> field_21 ohatra
# eo amreo field 2 reo ohatra no misy ny liaison amle table 2
# de ohatra (field_12 x field_22) no tiana ho azo
select (t1.field_12 * t2.field_22) as `produit` from table_1 t1
@irzhywau
irzhywau / cockroachdb-k8s.yaml
Created March 21, 2019 15:19
cockroachdb-k8s.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: cockroachdb
labels:
app: cockroachdb
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
@irzhywau
irzhywau / CacheDrivenCollection.php
Last active June 21, 2019 16:09
Retrieving data from cache
<?php
// this piece is wrapped in a method of the class in charge of handling data to / from cache
$this->bootCollection();
$dataset = $this->fetch($this->appViewStoragePath."{$app_id}-{$this->table->key}.json", true);
// --- Filter data (settings-based filters)
$dataset = $this->applyFilterAndSearch($dataset, $this->searchFilter);
// --- Filter data (user filters)
@irzhywau
irzhywau / appview.jsx
Created June 21, 2019 16:08
Rendering table on front
render() {
//change to let
let {columns, fields, cache, element_id} = this.props;
let {data, pages, loading, error} = this.state;
// get user session, unique for each browser
let sessionId = getPHPSessId();
const Error = ({error}) => (
<span style={{fontSize: "120%", color:"#ff0000", width:"100%", textAlign:"center", display:"inline-block"}}>Oops!! {error}</span>
@irzhywau
irzhywau / PodioItem.ts
Created June 21, 2019 16:15
Formatting data
// inside the formatter method
parallel(_map(item.fields, (field: any) => {
return (callback: Function) => {
let value: any = null;
switch (field.type) {
case 'category':
value = _map(field.values, (val: any) => { return { id: val.value.id, text: val.value.text } });
break;
case 'image':
@irzhywau
irzhywau / appview.ts
Last active June 21, 2019 16:21
Fetch complete dataset
parallelLimit(_map(offsets, o => (callback: Function) => {
if (cancelRequest) {
callback(new Error(`Request canceled by client`), null);
}
// we implemented retry pattern which focus on RateLimitError only
retry({
times: retries
, interval: function (retryCount) {
console.log(`retry... #${retryCount}, last client: ${podio.clientId}`);

Keybase proof

I hereby claim:

  • I am irzhywau on github.
  • I am irzhy (https://keybase.io/irzhy) on keybase.
  • I have a public key ASDIWYDt8qwr77P6AfGveU0kR2IQTiUymnu8aGoFNIRtqwo

To claim this, I am signing this object:

@irzhywau
irzhywau / ConnectorSelect.tsx
Created January 5, 2022 13:09
dapps browser connect attempts
// we are in an create-react-app context
export default () => {
const [mm, setSupport] = React.useState<MetamaskSupport | null>(null);
React.useEffect(() => {
let alreadyHandled = false;
// as the provider may be not available all the time on mobile, we need this side-effect implementation
// see https://docs.metamask.io/guide/mobile-best-practices.html#the-provider-window-ethereum
// also see https://github.com/MetaMask/detect-provider
@irzhywau
irzhywau / ERC20WrappableSupport.sol
Last active March 27, 2022 18:18
wrap/unwrap token inside of a contract
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.12;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./IERC20Wrappable.sol";
contract ERC20WrappableSupport {
modifier withWrap(address payable wToken) {
@irzhywau
irzhywau / HiveUploaderContext.js
Created August 9, 2022 08:29
Sandboxing hive and did authentication flow in a backend context
const { Logger, VerifiablePresentation, JWTHeader, JWTParserBuilder, Issuer, DIDURL } = require('@elastosfoundation/did-js-sdk')
const { AppContext, Vault, HiveException } = require('@elastosfoundation/hive-js-sdk')
const didConfig = require("../../config/elastos.did");
const hiveConfig = require("../../config/elastos.hive");
const { AppDID, UserDID } = require("./entities");
class ElacityHiveContext {
constructor(subFolder = null) {
this.localDataDir = `${didConfig.FOLDER.METADATA}/${(didConfig.APP.DID).split(':').pop()}` + (subFolder ? `/${subFolder}` : '');