Skip to content

Instantly share code, notes, and snippets.

@aarvay
aarvay / heap.js
Last active July 30, 2022 13:21
A small heap implementation
function Heap(data = [], compare = (a, b) => a < b) {
const heap = [null];
const size = () => heap.length - 1;
const leftIdx = (i) => i * 2
const rightIdx = (i) => i * 2 + 1
const parentIdx = (i) => Math.floor(i / 2);
const left = (i) => heap[leftIdx(i)];
const right = (i) => heap[rightIdx(i)];

Keybase proof

I hereby claim:

  • I am aarvay on github.
  • I am aarvay (https://keybase.io/aarvay) on keybase.
  • I have a public key ASDb9ANRc9gL3VzFa40siebRVVRvgSS6YQTaJH9ZYEiuHwo

To claim this, I am signing this object:

@aarvay
aarvay / poison_anomaly.exs
Created August 27, 2016 14:40
Anomaly in poison decoder
defmodule Payment do
@derive {Poison.Encoder, except: [:entity, :order_id]}
defstruct [:id, :amount, :currency, :status, :method, :description,
:refund_status, :amount_refunded, :email, :contact, :fee, :service_tax,
:error_code, :error_description, :notes, :created_at]
end
defmodule Collection do
@derive {Poison.Encoder, except: [:entity]}
@aarvay
aarvay / output.json
Created February 21, 2016 15:40
libgraphqlparser's ast_to_json()issue
{
"kind": "Document",
"loc": {
"start": 1,
"end": 2
},
"definitions": [
{
"kind": "OperationDefinition",
"loc": {
Build settings from command line:
CONFIGURATION_BUILD_DIR = /private/tmp/poison-FL5b/Poison/__build
=== BUILD TARGET DeepEnd OF PROJECT DeepEnd WITH CONFIGURATION Release ===
Check dependencies
Write auxiliary files
/bin/mkdir -p /Users/vignesh/Library/Developer/Xcode/DerivedData/Poison-fibuybwdaxbditdgbhpcalqdofrs/Build/Intermediates/DeepEnd.build/Release/DeepEnd.build
write-file /Users/vignesh/Library/Developer/Xcode/DerivedData/Poison-fibuybwdaxbditdgbhpcalqdofrs/Build/Intermediates/DeepEnd.build/Release/DeepEnd.build/DeepEnd-project-headers.hmap
@aarvay
aarvay / require.patch
Created March 27, 2012 08:01
Require Hack Patch
--- load-head.c 2012-03-27 11:29:29.000000000 +0530
+++ load.c 2012-03-27 11:26:22.000000000 +0530
@@ -4,21 +4,19 @@
#include "ruby/ruby.h"
#include "ruby/util.h"
-#include "internal.h"
#include "dln.h"
#include "eval_intern.h"
-
@aarvay
aarvay / require-perf-test.rb
Created March 23, 2012 20:14
A small test to measure require's performance
# When requiring 10K files ruby slows down like shit.
# Ruby before loading a file wants to make sure it's not already require'd.
# To do that it loops through a variable called $" and checks if this file is require'd.
class FileRequiredTest
PATH = "./hackathon/test/gen"
def main
`mkdir -p #{PATH} &2>1`
@aarvay
aarvay / gist:1341918
Created November 5, 2011 19:38
A RESTful API to check the PNR Status
<?php
require_once('pwi/phpQuery.php'); //Including phpQuery Library
/**
* The input for the REST api is got via "GET"
*/
$pnr1 = $_GET['pnr1']; //The first 3 digits of your PNR
$pnr2 = $_GET['pnr2']; //Remaining digits
@aarvay
aarvay / gitswitch.sh
Created October 7, 2011 10:01
Bash script to manage fake git accounts
#!/bin/bash
#Script to switch between the orginal git account and the fake one.
#Setup
#=====
# Have two folders named "key_backup" and "fake_backup" in ~/.ssh/
# The original account's pubkey will be stored in key_backup/ and fake account's in fake_backup/
# --Aarvay
[ "$(ls -A ~/.ssh/fake_backup)" ] && { mv ~/.ssh/id_rsa* ~/.ssh/key_backup/; mv ~/.ssh/fake_backup/id_rsa* ~/.ssh/; echo "Switched to Fake Account!"; } || { mv ~/.ssh/id_rsa* ~/.ssh/fake_backup/; mv ~/.ssh/key_backup/id_rsa* ~/.ssh/; echo "Switched to Original Account!"; }
@aarvay
aarvay / gist:1092113
Created July 19, 2011 12:08
Setting up the local repo
git remote add prod user@yourwebsite.com:yourwebsite.git
git push prod +master:refs/heads/master