Skip to content

Instantly share code, notes, and snippets.

@arbinish
arbinish / zmq-client.py
Created July 21, 2013 07:31
zmq echo client
import zmq
import sys
ctx = zmq.Context()
sock = ctx.socket(zmq.REQ)
sock.connect('tcp://localhost:3610')
for i in range(10):
print '%s -> ' % randMsg,
sys.stdout.flush()
@arbinish
arbinish / bootstrap-typeahead-sample
Created November 27, 2014 06:39
Bootstrap typeahead example. Handling a list of objects from API endpoint.
('input[type="text"]').typeahead
minLength: 3
quietMillis: 250
source: (query, process) ->
@options.map = {}
suggest = []
self = @
$.getJSON "api/users", {q: query}, (data) =>
$.each data, (idx, item) ->
ele = "#{item.fullname} (#{item.name})"
@arbinish
arbinish / loader-css
Created November 29, 2014 10:45
Quick CSS snipper for displaying spinner
#loader {
position: absolute;
background-repeat: no-repeat;
background-position: 50% 50%;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(255, 255, 255, 1);
z-index: 99;
@arbinish
arbinish / gist:4adaf590cf869f3c158e
Created March 5, 2015 16:50
db.session.dirty trick
from flask.ext.sqlalchemy import SQLAlchemy
from flask import Flask
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://db_user@localhost/employees'
db = SQLAlchemy(app)
class User(db.Model):
@arbinish
arbinish / pyexpect
Created April 19, 2015 18:01
Password automation
# coding: utf-8
import pty
import os
import sys
commands = ["some-command", "--with", "options"]
pid, child_fd = pty.fork()
if not pid:
os.execv(commands[0], commands)
import sys
from subprocess import PIPE, Popen
fd = open('/etc/fstab')
mounts = set([])
for line in fd:
line = line.strip()
if line.startswith('#'):
continue
mnt_point = line.split()
@arbinish
arbinish / contactform.js
Created December 24, 2015 13:29 — forked from insin/contactform.js
React contact form example
/** @jsx React.DOM */
var STATES = [
'AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI',
'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS',
'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR',
'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'
]
var Example = React.createClass({
@arbinish
arbinish / datatable-test.html
Created January 2, 2016 17:32
jquery datatable delete row based on a cell value
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DataTable Test</title>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css" media="screen" title="no title" charset="utf-8">
</head>
<body>
class AttrStorage(dict):
def __init__(self, fields=None, **kwargs):
""" only keys defined in fields are allowed """
self.fields = ()
if fields:
self.fields = fields
super(AttrStorage, self).__init__(kwargs)
def __getitem__(self, name):