Skip to content

Instantly share code, notes, and snippets.

View vik-y's full-sized avatar

Vikas Yadav vik-y

View GitHub Profile
@vik-y
vik-y / ftp-transfer.sh
Created December 30, 2014 13:52
Shell Script to Transfer 2 files to an ftp server
#!/bin/sh
HOST=''
USER=''
PASSWD=''
ftp -n $HOST <<END_SCRIPT
user $USER $PASSWD
binary
@vik-y
vik-y / change-extension.py
Created December 31, 2014 17:52
Change extension of all files in a given folder
import os, sys
files = os.listdir(os.getcwd())
for f in files:
x = f.split('.')
r = x[0] + '.extension' #The extension which you want to give to the file
os.renames(f, r)
@vik-y
vik-y / respawn.sh
Created January 6, 2015 15:48
Detect Failure in run time of a program and restart it
until <Shell Command to be Executed>; do
echo "Server 'myserver' crashed with exit code $?. Respawning.." >&2
sleep 1
done
@vik-y
vik-y / mysql.py
Last active August 29, 2015 14:13
Python MySQLdb example, is helpful in connecting Python with MySQL database
import MySQLdb
db = MySQLdb.connect(
host = 'localhost',
user = 'root',
passwd = '',
db = '',
unix_socket = '/opt/lampp/var/mysql/mysql.sock' #This is needed if you are using mysql of xampp installation, else you can remove this
)
@vik-y
vik-y / pyshell.py
Last active August 29, 2015 14:13
Run Shell Scripts from Python like subprocesses
import subprocess
def runCommand(comm):
'''
Using the subprocess library this runs the command passed
'''
proc = subprocess.Popen(comm.split(), stdout=subprocess.PIPE)
outputstr = ''
for line in proc.stdout.readlines():
outputstr+=line.rstrip()+"\n"
@vik-y
vik-y / pyrequests.py
Created January 15, 2015 18:33
Python Web Requests
import requests
#We often have to automate some task, using requests library can be pretty easy as we
#Dont have to bother about the headers which we send along with our call and lets us do things fast.
'''
Functions to send Simple get and post request along with payload
payload is a dictionary
cookie is also a dictionary of key value pair
@vik-y
vik-y / notify.py
Created March 25, 2015 07:16
Desktop Notifications in Python
import pynotify
def desktop_notify(title, message):
pynotify.init("Test")
notice = pynotify.Notification(title, message)
notice.show()
#Works like a charm on both windows and linux
@vik-y
vik-y / 0_reuse_code.js
Last active August 29, 2015 14:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
//tes
youtube-dl hacks
Use:
youtube-dl -c <link> //To resume download of a stopped file
youtube-dl -F <link> //Download after selecting the format of the file which you want to download
Example
-----------
@vik-y
vik-y / rcv.c
Last active August 29, 2015 14:17
Send a file - c socket
//Works perfectly with the send written above
char recvBuff[10];
int bytesReceived = recv(new_fd, recvBuff, 10, 0);
while(bytesReceived != 0)
{
// you should add error checking here
fwrite(recvBuff, bytesReceived, 1, outputFile);