Skip to content

Instantly share code, notes, and snippets.

View alvintamie's full-sized avatar

Alvin Francis Tamie alvintamie

View GitHub Profile
@alvintamie
alvintamie / parser-to-db-query.rb
Last active March 10, 2024 13:19
parser-to-query.rb
class Parser
def self.run
dataset = DB[Sequel[payload[:TenantID].to_sym][payload[:Entity].to_sym]]
dataset = dataset.order(Sequel.send(payload[:sortDirection].to_sym, payload[:sortBy].to_sym) ) if payload[:sortBy].present?
dataset = dataset.limit(payload[:PageSize]) if payload[:PageSize].present?
offset = payload[:PageSize] * (payload[:Page] - 1)
offset = 0 if offset < 0
@alvintamie
alvintamie / rest_example.json
Last active March 1, 2024 05:40
Rest Contract
{
"query”: {
“Account”: {
"arguments": {
"first": 5,
"after": "<x0>", // cursor next
"where": {
{
"AccountId": {
"inq": { // perform join AccountId where account id match following
@alvintamie
alvintamie / dynamic_resolver.py
Created March 1, 2024 05:04
Dynamic Resolver
import asyncio
from graphql import (
graphql, GraphQLSchema, GraphQLObjectType, GraphQLField, GraphQLString, GraphQLList, GraphQLInt,
GraphQLArgument, GraphQLInputObjectType, GraphQLInputField, GraphQLNonNull
)
# Mock data for Accounts and Contacts
mock_data = {
"Account": [
{"Id": 1, "Name": "Edge Communications", "Industry": "Telecommunications"},
@alvintamie
alvintamie / caching_example.go
Last active July 11, 2018 20:07
caching idea go
func Cache(key string, expirationTime int, f func() (interface{}, error)) (interface{}, error) {
logger.Info("Check caching if exist return the result immediately")
q, e := f()
logger.Info("Set result to cache")
return q, e
}
func (r *repository) ResolveQuestionSetBySerials(serials []string) (*[]RubelQuestionSet, error) {
questionSets, err := Cache("Test", 100, func() (interface{}, error) {
{
"success": true,
"data": [
{
"type": "query",
"text": "dress",
"score": 123
},
{
"type": "product",
import itertools
t = 31
cl = [10,9,8,4]
operations = ["+", "-", "*", "/"]
def r(a,b,o):
a = float(a)
$(this.refs.form.getDOMNode()).ajaxForm( {
xhrFields: {
withCredentials: true
},
error: function(response, status) {
console.log(response.responseText);
console.log(status)
},
success: function(response, status) {
console.log(response);
@alvintamie
alvintamie / gist:5a692454d588b187cd47
Last active August 29, 2015 14:13
Java Parse Time with Timezone
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.TimeZone;
public class ParseTimeWithTimezone{
public static void main(String []args){
try {
@alvintamie
alvintamie / MultitierVPC
Last active October 18, 2015 21:44
AWS Template CloudFormation for VPC
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Template multi-tier-web-app-in-vpc. It will create a multi-tier web applications in a VPC with multiple subnets. The first subnet is public and contains and internet facing load balancer, a NAT device for internet access from the private subnet and a bastion host to allow SSH access to the hosts in the private subnet. The second subnet is private and contains a Frontend fleet Security Group for EC2 instances",
"Parameters" : {
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type": "String",
import unittest
import os
import time
class Clock:
WORK_DAYS = 22
AVERAGE_SALARY = 4000.0
WORK_HOURS = 8