Skip to content

Instantly share code, notes, and snippets.

@vik-y
vik-y / sql-connect.r
Created October 25, 2016 05:44
Use sqlite table in R
library("RSQLite")
# connect to the sqlite file
driver <- dbDriver("SQLite")
con = dbConnect(driver, dbname="<absolute-path-to-sqlite-file>")
# get a list of all tables
alltables = dbListTables(con)
@vik-y
vik-y / hyundai.py
Created October 6, 2016 16:44
A script to extract cities in which hyundai's workshops are available
'''
Copyright (c) 2016 Vikas Yadav
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
@vik-y
vik-y / alive.py
Created September 13, 2016 09:04
Script to check if a given host is online or not
'''
Author: Vikas Yadav
Description:
Script to check if a given host is online or not
This will not work if the given host is blocking ping requests.
'''
import os
import re
import time
@vik-y
vik-y / get_ips.py
Last active January 17, 2019 15:52
Script to get all unused ips in a subnet
import os, sys
# Fping must be installed in the system
os.system('fping -a -g %s/24 > alive.txt' % (sys.argv[1]))
f = open('alive.txt', 'r')
raw = f.readlines()
ips = [int(x.split('.')[-1].strip()) for x in raw]
ips.sort()
@vik-y
vik-y / MergeSort.java
Last active August 21, 2016 18:33 — forked from jayeshsolanki93/MergeSort.java
MergeSort in Java
import java.util.Arrays;
import java.util.Scanner;
class MergeSort {
private static Scanner sc;
public static void main(String args[]) {
sc = new Scanner(System.in);
System.out.println("Enter no of terms");
@vik-y
vik-y / ovs-connect.py
Last active August 21, 2016 17:32
Script to help in operating ovs on ubuntu
'''
Author : Vikas Yadav
DISCLAIMER:
Running this script requires root privileges
You can loose internet connectivity after using this script. So proceed with
caution.
This should not be used on systems which have two physical interfaces connected
to internet.
This should not be used on system which already has a ovs bridge up and running.
@vik-y
vik-y / pi_email.txt
Last active December 24, 2016 12:25
Pi Email Test
21
@vik-y
vik-y / learn.ml
Created May 4, 2016 17:42
Ocaml Basics
(*
* This document contains code written to learn Ocaml before the
* Ocaml quiz.
* Let's do this in a hope to learn Ocaml properly.
* Author: Vikas Yadav
* Email: [email protected]
*)
(* Definition of Union/Record Types *)
type number = Integer of int | Rational of int * int ;;
@vik-y
vik-y / num.ml
Last active April 18, 2016 18:34
Modified version of decimal number identifier
let num (s : char Mystream.mystream) : State.state =
let rec one (stream : char Mystream.mystream) : State.state =
match stream with
Mystream.End -> State.Terminate(true)
| Mystream.Cons(c, _) ->
let lookahead = (Mystream.tl stream) () in
if (c >= '0' && c <= '9') then
match lookahead with
Mystream.Cons(c', _) ->
if (c' >= '0' && c' <= '9') then
@vik-y
vik-y / get-post.js
Last active March 23, 2016 15:11
Node js. Doing a get and post request, parsing a json
/*
This code might be useful for writing get and post requests and rendering json files when you are using node js
*/
var request = require('request');
base_url = ""
function getComplaints(wardName, callback){
request(base_url+'getComplaints.json?name='+wardName, function (error, response, body) {
if (!error && response.statusCode == 200) {
//console.log(body); // Print the google web page.