Skip to content

Instantly share code, notes, and snippets.

@ovidiucs
ovidiucs / array-of-strings.c
Created September 23, 2012 20:41
Pointer Offset and Subscript Operator Syntax
#include<stdio.h>
#include<strings.h>
int main(void)
{
/* Looping Variables */
int i = 0, j = 0;
int num_states = 4;
char *states[]= {"California","Oregon","Washington","Texas"};
@ovidiucs
ovidiucs / email-when-disk-is-below-limit.sh
Created October 4, 2012 18:49 — forked from scorpio2k2/gist:3835412
Send email to when disk is below a limit
#!/bin/sh
#The limit is 30% now
limit=10
mail=contact@debian-tutorials.com
tmp_file=/tmp/diskusage
hostname=`hostname`
#Now the script will calculate the current disk usage
disk=$(df -h | awk 'FNR == 2 {print $5}' | sed 's/%//')
// Wanted to check out the example from Frontend Masters by David Crockford
var template = '<table border="{border}">' + //
'<tr><th>Last</th><td>{last}</td></tr>' + // Hold table format in var template
'<tr><th>First</th><td>{first}</td></tr>' + //
'</table>'; //
var data = { // values to be replaced with RegEx
first: "Carl", //
last: "Jose", //
var myClosure = function() {
var date = new Date();
var nested = function() {
return date.getMilliseconds();
};
return {
foo: nested
};
};
@ovidiucs
ovidiucs / .screenrc
Last active August 29, 2015 14:00
screenrc
escape ^A^A
term screen-256color
vbell off
startup_message off
defscrollback 10000
hardstatus off
hardstatus alwayslastline
# hardstatus string "%{kG}%50>%-w%{ky}%n %t%{-}%+w%{-} %>%=%{ky}Ctrl-A ?%{-} for help"
#hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W} %c %{g}]'
hardstatus string '%{= kG}[%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W} %c %{g}]'
@ovidiucs
ovidiucs / subnetloop.py
Last active August 29, 2015 14:21
Subnet for loop for IPv4
units = [1 << (8*i) for i in range(3,-1,-1)]
def ip_to_int(ip):
return sum(int(byte) * unit for(byte,unit) in zip(ip.split('.'), units))
def int_to_ip(i):
return '.'.join(str((i/bit) & 0xff) for bit in units)
start_ip = '1.0.0.0'
end_ip = '1.0.0.255'
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(16), index=True, unique=True)
username = db.Column(db.String(16), index=True, unique=True)
password_hash = db.Column(db.String(64))
def set_password(self, password):
@ovidiucs
ovidiucs / Class2.py
Last active August 29, 2015 14:21
Explaining Classes
class MyClass(object):
"""A simple class example"""
# Class OBJECTS support two kinds of operations
# 1. Attribute reference
# 2. Instantiation
i = 12345
def something(self):
print 'printing - hello world'
return "returning - Hi"
@ovidiucs
ovidiucs / paramiko-proxy.py
Last active October 12, 2023 16:53
Paramiko Connect via proxy
#!/usr/bin/env python
#-*- coding:utf8 -*-
# sources
# 1. https://gist.github.com/tell-k/4943359#file-paramiko_proxycommand_sample-py-L11
# 2. https://github.com/paramiko/paramiko/pull/97
# info: http://bitprophet.org/blog/2012/11/05/gateway-solutions/
# local -> proxy-server -> dest-server
# ~/.ssh/config
#
# Host proxy-server
'''
Requires paramiko >=1.8.0 (paramiko had an issue with multiprocessing prior
to this)
Example code showing how to use netmiko for multiprocessing. Create a
separate process for each ssh connection. Each subprocess executes a
'show version' command on the remote device. Use a multiprocessing.queue to
pass data from subprocess to parent process.
Only supports Python2