Recent Updates Toggle Comment Threads | Keyboard Shortcuts

  • yalamber 9:48 am on May 2, 2022 Permalink  

    Custom graphql field with array type for archive dates 

    function get_monthly_archive_array()
    {
        $years      = [];
        $years_args = [
            'type'      => 'monthly',
            'format'    => 'custom',
            'before'    => '',
            'after'     => '|',
            'echo'      => false,
            'post_type' => 'post',
            // 'order'     => 'ASC',
        ];
    
        // Get Years
        $years_content = wp_get_archives($years_args);
    
        if (!empty($years_content)) {
            $years_arr = explode('|', $years_content);
    
            // Remove empty whitespace item from array.
            $years_arr = array_filter($years_arr, function ($item) {
                return trim($item) !== '';
            });
    
            foreach ($years_arr as $year_item) {
    
                $year_row = trim($year_item);
                preg_match('/href=["\']?([^"\'>]+)["\']>(.+)<\/a>/', $year_row, $year_vars);
    
                if (!empty($year_vars) &amp;&amp; is_array($year_vars)) {
                    $year_url = !empty($year_vars[1]) ? $year_vars[1] : ''; // Eg: http://demo.com/2021/11/
                    $parts    = parse_url($year_url);
                    $path     = !empty($parts['path']) ? $parts['path'] : '';
    
                    $years[] = [
                        'name'  => $year_vars[2], // Eg: November 2021
                        'slug' => $path // Eg: /2021/11/ , so that we can prefix o suffix our own URL.
                    ];
                }
            }
        }
    
        return $years;
    }
    
    add_action('graphql_register_types', 'xyz_register_archive_type');
    
    function xyz_register_archive_type()
    {
        register_graphql_object_type('XYZArchiveDate', [
            'description' => __("Archive liks", 'xyz'),
            'fields' => [
                'name' => [
                    'type' => 'String',
                    'description' => __('The name of the archive date', 'dcc'),
                ],
                'slug' => [
                    'type' => 'String',
                    'description' => __('The slug value of archive', 'dcc'),
                ],
            ],
        ]);
    }
    
    add_action('graphql_register_types', 'xyz_extend_archive_wpgraphql_schema');
    
    function xyz_extend_archive_wpgraphql_schema()
    {
        register_graphql_field('RootQuery', 'archiveDates', [
            'type' => ['list_of' => 'XYZArchiveDate'],
            'description' => __('Returns archive dates', 'xyz'),
            'resolve' => function () {
                return get_monthly_archive_array();
            }
        ]);
    };
    
     
  • yalamber 1:41 pm on December 23, 2021 Permalink |
    Tags: blockchian, grpc, Iotex   

    RPC call to read state of iotex blockchian and get voters bucket list

         import RpcMethod from 'iotex-antenna/lib/rpc-method';
         import { IReadStakingDataMethodToBuffer, IReadStakingDataMethodName, 
            IReadStakingDataRequestToBuffer } from 'iotex-antenna/lib/rpc-method/types';
         import { VoteBucketList } from 'iotex-antenna/protogen/proto/types/state_data_pb';
    
          const ioAddress = from(god.currentNetwork.account)?.string();
          const state = await provider.readState({
            protocolID: Buffer.from('staking'),
            methodName: IReadStakingDataMethodToBuffer({
              method: IReadStakingDataMethodName.BUCKETS_BY_VOTER
            }),
            arguments: [
              IReadStakingDataRequestToBuffer({
                bucketsByVoter: {
                  voterAddress: ioAddress,
                  pagination: {
                    offset: 0,
                    limit: 1000
                  }
                }
              })
            ],
            height: undefined
          });
          let voteBucketList = VoteBucketList.deserializeBinary(state.data);
          const voteBucketListObj = VoteBucketList.toObject(false, voteBucketList);
          console.log(voteBucketListObj)
    
     
  • yalamber 4:51 pm on July 1, 2021 Permalink |
    Tags:   

    Delete all files except specific filenames in linux
    rm -v !(“filename1″|”filename2”)

     
  • yalamber 4:50 pm on July 1, 2021 Permalink |
    Tags:   

    Delete all files except specific filenames in linux
    rm -v !(“filename1″|”filename2”)

     
  • yalamber 6:04 am on November 14, 2020 Permalink |
    Tags: opensource, video   

    https://matrix.org/

     
  • yalamber 4:22 am on November 14, 2020 Permalink |
    Tags: deploy, rails, ruby   

    https://gorails.com/deploy/ubuntu/20.04#next-steps

     
  • yalamber 9:31 am on May 2, 2020 Permalink |
    Tags:   

    Stop and remove all docker container. 

    docker stop $(docker ps -a -q)
    docker rm $(docker ps -a -q)
    
     
  • yalamber 9:30 am on May 2, 2020 Permalink |
    Tags:   

    Running a container in another container network mode 

    So I had a docker image which had database host hardcoded to localhost, So in network_mode in docker compose file we could use container’s name to run in same network so that it is accessible through localhost.

     network_mode: "container:thinger"
    
     
  • yalamber 9:41 am on January 6, 2020 Permalink |
    Tags: mobile development, react   

    React Native still is better solution than flutter in a true cross platform sense 🙂

     
  • yalamber 3:51 pm on November 26, 2019 Permalink |
    Tags:   

    Update all docker images at once

    docker images |grep -v REPOSITORY|awk '{print $1}'|xargs -L1 docker pull 
    
     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel