Skip to content

Instantly share code, notes, and snippets.

View asdacap's full-sized avatar

Amirul Ashraf asdacap

View GitHub Profile
@asdacap
asdacap / serde_chrono_dateformat.rs
Created May 14, 2021 17:59
Snippet to specify custom date format when using Serde and Chrono
use serde::Deserialize;
use serde_json;
use chrono::{DateTime,Utc,NaiveDateTime,NaiveDate};
#[derive(Debug, Deserialize)]
struct TheStruct {
#[serde(deserialize_with = "datetime_deserializer")]
time: DateTime<Utc>,
}
import com.github.jsonldjava.core.RDFDataset
import com.github.jsonldjava.core.RDFDatasetUtils
import org.apache.commons.codec.binary.Hex
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.collections4.iterators.PermutationIterator
/**
* Normalize jsonld-java's RDFDataset using URDNA2015 specification
*
* Passes json-gold tests
@asdacap
asdacap / bind-observable.directive.ts
Created March 20, 2018 09:38
Easy Angular RxJS view binder/resolver.
import {
Component, ComponentFactoryResolver, Directive, Input, OnDestroy, OnInit, TemplateRef,
ViewContainerRef
} from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { ReplaySubject } from 'rxjs/ReplaySubject';
/**
* Do you love reactive streams? But hate subscribing to them, setting them to a local
@asdacap
asdacap / LoadableResource.js
Last active March 6, 2018 02:10
A pattern I like to use in react-redux app.
// @flow
import * as _ from 'lodash'
import invariant from 'invariant'
/**
* A LoadableResource is a monad that wraps a resource, which may be in the
* four state
* - missing
* - pending
* - error
@asdacap
asdacap / transform.js
Created March 9, 2017 14:42
ReactNative transformer that works well with typescript, or any preprocessor that output sourcemaps, which should then be fed to react-native packager.
/**
* Its a copy of the built in transformer, but instead of a somewhat
* two stage approach, it pass directly to babel, which allow things like
* sourceMap merging.
*
* Also, it assume .babelrc is always available
*/
const babel = require('babel-core');
const externalHelpersPlugin = require('babel-plugin-external-helpers');
@asdacap
asdacap / Input 1
Last active January 14, 2017 13:27
All-IT Superstore
=================
Date: 12 January 2016
Receipt No: 87129380982
Item : Quantity : Price (per item)
-----------------------------------------------------
1. Kicap : 5 : RM 5.50
2. Gigabyte G502 : 1 : RM 309.00
"""""""""""""""""""""
"""" COMPETE STUFF
map <S-F2> :!g++ -std=c++11 % -o %:r.out<CR>
map <F2> :!g++ -std=c++11 -DDEBUG -Wfatal-errors % -o %:r.out<CR>
map <F3> :!./%:r.out < %:p:h/input<CR>
map <S-F3> :!./%:r.out < %:p:h/input \| diff %:p:h/answer - <CR>
map <F4> :!javac %<CR>
#include<bits/stdc++.h>
using namespace std;
#define SET(t,v) memset((t), (v), sizeof(t))
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize( unique( ALL(c) ) - (c).begin() )
#if __cplusplus > 199711L
#define ItREP(it,c) for(auto it = (c).begin(); it!= (c).end(); it++)
#define REP(i,n) for(decltype(n) i=0;i<n;i++)