Skip to content

Instantly share code, notes, and snippets.

View ardani's full-sized avatar
🎯
Focusing

Ardani Rohman ardani

🎯
Focusing
View GitHub Profile
const {map, first} = require('lodash');
const resolvers = {
Query: {
hero: async (_, {id}, {dataSources}) => {
const res = await dataSources.marvelApi.getHero(id);
const data = res.data;
const item = first(data.results);
return {
id: item.id,
const crypto = require('crypto');
const { RESTDataSource } = require('apollo-datasource-rest');
const { ApolloError } = require('apollo-server-errors');
class MarvelApi extends RESTDataSource {
constructor() {
super();
this.baseURL = 'https://gateway.marvel.com:443/v1';
}
@ardani
ardani / exported_code.txt
Created May 11, 2021 07:51
export code power suite rank tracker
<[DEFINE name="dateFormat" value="exportData.createDateFormat('yyyy-MM-dd')"/]>
<[DEFINE name="keywords" value="exportData.keywords"/]>
<[DEFINE name="searchEngines" value="exportData.searchEngines"/]>
date,keyword,search_engine,rank
<[FOR_EACH name="keywords" id="keyword"]>
<[FOR_EACH name="searchEngines" id="searchEngineType"]>
<[DEFINE name="history" value="keyword.getHistory(searchEngineType)"/]>
<[FOR_EACH name="exportData.reverse(history)" id="historyRecord"]>
"<[ECHO text="dateFormat.format(historyRecord.checkDate)"/]>",<[ECHO text="keyword.query"/]>,<[ECHO text="searchEngineType.getName()"/]>,<[DEFINE name="position" value="exportData.getPosition(historyRecord)"/]><[IF condition="position != null"]><[THEN]><[ECHO text="position"/]><[/THEN]><[/IF]>
<[/FOR_EACH]>
@ardani
ardani / api.example.conf
Created April 27, 2021 11:01 — forked from sky93/api.example.conf
Map Laravel /api route to api subdomain in Nginx
server {
listen 80;
server_name api.example.com;
location / {
root /usr/share/nginx/LARAVEL_DIR/public;
index index.php;
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
@ardani
ardani / flow-error-icu4c-not-loaded.md
Created June 11, 2020 04:50 — forked from berkedel/flow-error-icu4c-not-loaded.md
dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib

How to solve dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.60.dylib

brew uninstall --ignore-dependencies node icu4c
brew install node
@ardani
ardani / progress_bar.php
Created July 29, 2019 05:30 — forked from mayconbordin/progress_bar.php
PHP CLI progress bar in 5 lines of code
<?php
function progress_bar($done, $total, $info="", $width=50) {
$perc = round(($done * 100) / $total);
$bar = round(($width * $perc) / 100);
return sprintf("%s%%[%s>%s]%s\r", $perc, str_repeat("=", $bar), str_repeat(" ", $width-$bar), $info);
}
<?php
use GuzzleHttp\Promise\EachPromise;
use GuzzleHttp\Promise\FulfilledPromise;
use GuzzleHttp\Psr7\Response;
use Cache;
$users = ['one', 'two', 'three'];
$cache = new Cache();
$promises = (function () use ($users, $cache) {
<?php
use GuzzleHttp\Promise\EachPromise;
use GuzzleHttp\Psr7\Response;
$users = ['one', 'two', 'three'];
$promises = (function () use ($users) {
foreach ($users as $user) {
// don't forget using generator
<?php
use GuzzleHttp\Promise\Promise;
$promise = new Promise();
$promise->then(
// $onFulfilled
function ($value) {
echo 'The promise was fulfilled.';
},
// $onRejected
<?php
$promise = $client->getAsync('http://httpbin.org/get');
$promise = $client->deleteAsync('http://httpbin.org/delete');
$promise = $client->headAsync('http://httpbin.org/get');
$promise = $client->optionsAsync('http://httpbin.org/get');
$promise = $client->patchAsync('http://httpbin.org/patch');
$promise = $client->postAsync('http://httpbin.org/post');
$promise = $client->putAsync('http://httpbin.org/put');