Skip to content

Instantly share code, notes, and snippets.

View jdkanani's full-sized avatar
🎯
Focusing

Jaynti Kanani jdkanani

🎯
Focusing
View GitHub Profile
@jdkanani
jdkanani / vuefire-init.js
Created August 28, 2017 19:28
vuexfire + vuefire
import Vue from 'vue';
import { VueFireMixin, firebaseMutations, bind, unbind } from '~/plugins/vuefire';
// vuefire init
export default function ({ store }) {
// use object-based merge strategy
// TODO This makes impossible to merge functions
const mergeStrats = Vue.config.optionMergeStrategies;
mergeStrats.firebase = mergeStrats.methods;
@jdkanani
jdkanani / decorators.js
Created August 2, 2017 11:06
Javascript decorators
export function sleepFor (timeInMilliSeconds = 1000) {
return new Promise((resolve, reject)=>{
setTimeout(resolve, timeInMilliSeconds);
});
}
export function waitFor (...names) {
return (target, prop, descriptor) => {
const fn = descriptor.value;
let newFn = function (...args) {
@jdkanani
jdkanani / fetch-block-promise.js
Last active August 15, 2017 09:45
Fetches Ethereum block data using web3 APIs
export function fetchBlock (web3, blockNumber) {
return web3.eth.getBlock(blockNumber);
}
export function fetchTransactions (web3, txs) {
return new Promise((resolve, reject)=>{
let result = [];
let _resolved = false;
let callback = (err, obj) => {
@jdkanani
jdkanani / README.md
Last active August 20, 2018 10:25
testchain - Javascript test blockchain (testing purpose only)

Quick start

(set up two connected nodes and mine 1 block)

npm install
HTTP_PORT=3001 P2P_PORT=6001 npm start
HTTP_PORT=3002 P2P_PORT=6002 PEERS=ws://localhost:6001 npm start
curl -H "Content-type:application/json" --data '{"data" : "Some data to the first block"}' http://localhost:3001/mineBlock

HTTP API

@jdkanani
jdkanani / keybase.md
Created June 4, 2017 10:46
keybase.md

Keybase proof

I hereby claim:

  • I am jdkanani on github.
  • I am jdkanani (https://keybase.io/jdkanani) on keybase.
  • I have a public key whose fingerprint is 8A3D 2354 49B2 0A6A 94FE EA38 4396 982C 976B AE5E

To claim this, I am signing this object:

@jdkanani
jdkanani / app.yaml
Created December 28, 2015 16:52
Static google app engine config file
application: static-doc
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /(.+)
static_files: public/\1
upload: public/(.*)
@jdkanani
jdkanani / boards.txt
Created December 24, 2015 14:35
ATmega328 on a breadboard (8 MHz internal clock)
##############################################################
atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)
atmega328bb.upload.protocol=stk500
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600
atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
@jdkanani
jdkanani / server.js
Last active August 29, 2015 14:09 — forked from ziahamza/server.js
var http = require('http'),
fs = require('fs'),
path = require('path'),
exec = require('child_process').exec;
function pipeDoc(inputPath, finalType, stream) {
var finalPath = path.dirname(inputPath)
+ "/" + path.basename(inputPath).split('.')[0] + ".html";
var convCommand = 'unoconv -f ' + finalType + " " + inputPath;
exec(convCommand,function(err, stdout, stderr) {
@jdkanani
jdkanani / sudoku.py
Created January 13, 2014 14:07
Solving sudoku in Python : some changes to Peter Norvig's soultion Refer: http://norvig.com/sudoku.html
#!/usr/bin/env python
def cross(A, B):
return [a + b for a in A for b in B]
digits = '123456789'
letters = 'ABCDEFGHI'
rows = letters
cols = digits
@jdkanani
jdkanani / save-and-fetch.js
Last active December 18, 2015 17:59
This example demonstrates how to incrementally load and save object graphs using Backbone-associations. This is important because rarely, there would be a need to fetch (or save) a entire object hierarchy from the server.
var MyApp = {
context: {}
};
MyApp.context.departments = null;
MyApp.context.employees = null;
var counter = 100;
/**
* Initialization of associated models