Skip to content

Instantly share code, notes, and snippets.

View sarbajitc's full-sized avatar

Sarbajit Chatterjee sarbajitc

  • Bangalore, India
View GitHub Profile
@sarbajitc
sarbajitc / example.js
Last active June 17, 2018 05:21
Regex pattern matching
(\d+)\s+(Connected|Disconnected)\s+(Active|Idle|Connecting)\s+(Yes|No)\s+(Equal|Master|Slave)
@sarbajitc
sarbajitc / example.js
Created June 17, 2018 05:23
Regex pattern matching
(\d+)\s+(?:Connected|Disconnected)\s+(?:Active|Idle|Connecting)\s+(?:Yes|No)\s+(?:Equal|Master|Slave)
@sarbajitc
sarbajitc / example.py
Last active June 23, 2018 03:57
Simple employee object
"""
Employee class represents the employee data
"""
def __init__(self, emp_id, name, addr, salary):
self.id = emp_id
self.name = name
self.addr = addr
self.salary = salary
@sarbajitc
sarbajitc / views.py
Last active June 23, 2018 03:56
Django views.py for OpenStack Horizon
from horizon import tables
from .tables import TabledisplayTable
class IndexView(tables.DataTableView):
table_class = TabledisplayTable
template_name = 'project/tabledisplay/index.html'
def get_data(self):
strobj = '[{"id": 111, "name": "emp1", "salary": 1000, "addr": "kolkata"}, {"id": 222, "name": "emp2", "salary": 5000, "addr": "bangalore"}]'
instances = json.loads(strobj)
@sarbajitc
sarbajitc / tables.py
Last active June 23, 2018 03:54
Django tables.py for OpenStack Horizon
from horizon import tables
from django.utils.translation import ugettext_lazy as _
class TabledisplayTable(tables.DataTable):
name = tables.Column("name",
verbose_name=_("Employee Name"))
salary = tables.Column("salary", verbose_name=_("Salary in Rs"))
addr = tables.Column("addr",
verbose_name=_("Address"))
@sarbajitc
sarbajitc / template.html
Last active June 23, 2018 03:53
Django template for OpenStack Horizon
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Table Display" %}{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Employee Table Display") %}
{% endblock page_header %}
{% block main %}
{{ table.render }}
@sarbajitc
sarbajitc / time_check.py
Created June 23, 2018 04:00
Find time in python
import time
epoch_time_in_local_timezone = time.time()
@sarbajitc
sarbajitc / find_time.py
Created June 23, 2018 04:01
Find time in python
import calendar, datetime
current_utc_time_in_sec = calendar.timegm(datetime.datetime.utcnow().utctimetuple())
@sarbajitc
sarbajitc / trigger.sql
Last active June 28, 2019 05:47
Mysql trigger creation
DELIMITER @@
CREATE TRIGGER Test_Trigger
AFTER INSERT ON MyTable
FOR EACH ROW
BEGIN
DECLARE cmd CHAR(255);
DECLARE result int(10);
SET cmd=CONCAT('sudo /home/sarbac/hello_world ','Sarbajit');
SET result = sys_exec(cmd);
@sarbajitc
sarbajitc / tail_log.py
Created June 23, 2018 04:17
Tail log file in python
# maybe the log got rotated out from under us?
if stat(self.path)[ST_SIZE] <= self.pos: # modified by sarbajit
# file got truncated and/or re-created
self._reset()