Skip to content

Instantly share code, notes, and snippets.

View bngsudheer's full-sized avatar

Sudheer Satyanarayana bngsudheer

View GitHub Profile
@bngsudheer
bngsudheer / fen-to-svg.py
Created May 21, 2017 12:15
FEN to SVG:
import chess, sys
import chess.svg
# Install python-chess to your Python3 virtualenv
# virtualenv -p python3 ~/path/to/myvenv
# source /path/to/myvenv/bin/activate
# Usage: python3 fen-to-svg.py 'myfenstring' outputfilename
# or /path/to/myvenv/bin/python3 fen-to-svg.py 'myfenstring' outputfilename
fen = sys.argv[1]
file_name = '{}.svg'.format(sys.argv[2])
>>> line = '\something'
>>> line
'\\something'
>>> line.startswith('\some')
True
>>> line.startswith('\\some')
True
import time
string_to_add = 'my_new_characters'
file_name = 'my_file.{}'.format(time.time())
file_name = '{}{}'.format(file_name, string_to_add)
with open(file_name, 'w') as outfile:
outfile.write('hello')
import time
file_name = 'my_file.{}'.format(time.time())
with open(file_name, 'w') as outfile:
outfile.write('hello')
def flatten(my_list):
for a in my_list:
if not a:
continue
for b in a:
yield b
@bngsudheer
bngsudheer / od.py
Created September 27, 2016 18:51
od.py
from math import sqrt, sin
import numpy as np
import matplotlib.pyplot as plt
d = 0.8
data = []
x_values = []
theta_values = []
n_values = []
@bngsudheer
bngsudheer / webpack.config.js
Last active July 27, 2016 09:33
Webpack config to make a build using ES6 sources
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: "./index.js",
output: {
path: __dirname,
filename: "build.js"
},
@bngsudheer
bngsudheer / line-chart-d3js-example.html
Created June 11, 2016 08:12
Line chart example using d3.js
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
@bngsudheer
bngsudheer / find-badass-process-outbound-ssh.sh
Created March 11, 2016 14:47
Find the process that tries to establish outbound SSH connections
#!/bin/bash
# Find process that tries to establish outbound SSH connections
for (( ; ; ))
do
sleep 1
lsof -i tcp:22 -P -R
if [ $? -eq 0 ]; then
echo 'found something. See above for details'
exit
else
@bngsudheer
bngsudheer / function-dictionary-args.py
Created November 23, 2015 09:12
Pass keyword arguments using a dictionary
# You can nicely pass the dictionary items as keyword arguments
def my_function(a, b, c):
print a, b, c
# Pass keyword arguments
my_function(a=10, b=20, c=30)
args_dict = {'a': 100, 'b': 200, 'c':300}
# Pass keyword arguments using a dictionary
# The dictionary keys map to names of the keyword arguments