Skip to content

Instantly share code, notes, and snippets.

View jangeador's full-sized avatar
🐵

Delio Castillo jangeador

🐵
View GitHub Profile
@jangeador
jangeador / month_generator.py
Last active August 29, 2015 14:05
Generate a list of the months of the year in Python
'''
Generate a sorted list with the months of the year
'''
import datetime
months = [datetime.date(2000, m, 1).strftime('%m - %B') for m in range(1, 13)]
print months
'''
print months
['01 - January', '02 - February', '03 - March', '04 - April', '05 - May', '06 - June', '07 - July', '08 - August', '09 - September', '10 - October', '11 - November', '12 - December']
@jangeador
jangeador / get_or_create.py
Last active December 6, 2023 04:57
A function that creates unique objects based on models
def get_or_create(session, model, **kwargs):
'''
Creates an object or returns the object if exists
credit to Kevin @ StackOverflow
from: http://stackoverflow.com/questions/2546207/does-sqlalchemy-have-an-equivalent-of-djangos-get-or-create
'''
instance = session.query(model).filter_by(**kwargs).first()
if instance:
return instance
else:
# Brings all files from subdirectories to the root or to a designated folder
# to move to another folder substitute "." with the destination
# the backup=numbered option keeps files with the same name using a number
find /src/dir -type f -exec mv --backup=numbered -t /dst/dir {} +
@jangeador
jangeador / LimitSentMessages.ps1
Last active August 29, 2015 14:06
Limit the number of messages that an administrator can send Exchange 2010
# To create a new policy where the users can send to 30 recipients a day
# and no more than 1 message per minute, you would use this command:
New-ThrottlingPolicy -Name LimitMessagesSent -RecipientRateLimit 30 -MessageRateLimit 1
# To assign it to a user, use this command:
Set-Mailbox -Identity user_alias -ThrottlingPolicy LimitMessagesSent
@jangeador
jangeador / find_object_in_list.py
Last active August 29, 2015 14:06
Find object in list of objects or return None
next((x for x in test_list if x.value == value), None)
'''
This gets the first item from the list that matches the condition, and returns None if no item matches. It's my preferred single-expression form.
However,
'''
for x in test_list:
if x.value == value:
print "i found it!"
break
@jangeador
jangeador / 0_reuse_code.js
Last active August 29, 2015 14:06
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
@jangeador
jangeador / generate_keypair.sh
Last active August 29, 2015 14:06
Command to generate a key pair
ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
@jangeador
jangeador / rules.bat
Created October 31, 2014 17:46
Firewall Rules to Allow VEEAM to backup a Hyper-V Host
REM Rules are from here: http://www.veeam.com/kb1518
REM On Hyper-V Host Server open these ports
netsh advfirewall firewall add rule name="VEEAM Backup and Replication TCP" dir=in action=allow protocol=TCP localport=135,137-139,445
netsh advfirewall firewall add rule name="VEEAM Backup and Replication UDP" dir=in action=allow protocol=UDP localport=135,137-139,445
netsh advfirewall firewall add rule name="VEEAM Installer Service" dir=in action=allow protocol=TCP localport=6160
netsh advfirewall firewall add rule name="VEEAM Backup Proxy Service" dir=in action=allow protocol=TCP localport=6162
netsh advfirewall firewall add rule name="VEEAM vPower NFS Service" dir=in action=allow protocol=TCP localport=6161
netsh advfirewall firewall add rule name="VEEAM vPower NFS Service" dir=in action=allow protocol=TCP localport=6161
netsh advfirewall firewall add rule name="VEEAM Standard NFS Ports TCP" dir=in action=allow protocol=TCP localport=111,2049-2059,1058-1068
netsh advfirewall firewall add rule name="VEEAM Stand
@jangeador
jangeador / fabfile_gist.py
Created November 4, 2014 18:31
A script to backup several switches at once
from fabric.api import run, env, settings
extreme_switches = {'172.31.100.21': 'RDSL-S042-DCore-1',
'172.31.100.22': 'RDSL-S042-DCore-2',
'172.31.100.41': 'GES-S042',
'172.31.100.61': 'DSDS-S042',
'172.31.100.81': 'DV-S042',
'172.31.100.101': 'SWJH-S042',
'172.31.100.121': 'EP-S042',
'172.31.100.141': 'AZD-S042',
@jangeador
jangeador / temperature.cpp
Created January 12, 2015 15:11
Temperature Converter (From my early college days!)
/* Delio Castillo
BIS 221 C++
Charles Godfrey, Instructor
Spring 2002
Project Name : Project03A
Purpose of Program
To convert temperatures from Celsius to