Skip to content

Instantly share code, notes, and snippets.

@thisboyiscrazy
thisboyiscrazy / O365_Contacts_Calendars_Defaults_Reviewer.ps1
Created May 31, 2017 18:56
Set All Contact and Calander Default to Reviewer
Get-Mailbox | ForEach-Object {
Set-MailboxFolderPermission ${_}:\calander -User default -AccessRights Reviewer
Set-MailboxFolderPermission ${_}:\contacts -User default -AccessRights Reviewer
}
Import-Module MSOnline
$cred = Get-Credential
Connect-MsolService –Credential $cred
$users = Get-MsolUser -All | ?{ $_.isLicensed -eq "TRUE" }
$sku = "tenent:SMB_BUSINESS_PREMIUM"
$users | ?{ ($_.Licenses | ?{ $_.AccountSkuId -eq $sku}).Length -gt 0}
@thisboyiscrazy
thisboyiscrazy / o365_exchange.ps1
Last active April 21, 2016 19:16
Power shell connect to office 365
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session
@thisboyiscrazy
thisboyiscrazy / exchange_create_firstl_alias.ps1
Last active April 21, 2016 19:10
Add first name + first letter of last name alias to all users in exchange
Get-Mailbox -resultsize unlimited |ForEach-Object {
$u = $_ | Get-User
if ($u.Lastname.length -gt 1 -and $u.FirstName.length -gt 0) {
$new = (($u.FirstName) + ($u.LastName.Substring(0,1))).tolower() + "@example.com"
Set-Mailbox $_.id -EmailAddress @{add=$new}
}
}
@thisboyiscrazy
thisboyiscrazy / searchhighlow
Last active August 29, 2015 13:55
Binary search the return value of f for the closest value v is between starting with min going to max.
var searchHighLow = function(v,f,min,max) {
var t, dat;
for (;;) {
dat = f(min);
if(dat === v) return [min,min];
t = (min + max) >> 1;
dat = f(t);
if(dat === v) return [t,t];
@thisboyiscrazy
thisboyiscrazy / django_nose_transaction_test.py
Created May 2, 2013 15:50
A class for django nose testing that work with test generators and also uses transations
from django.db import transaction
from django.test.testcases import disable_transaction_methods, restore_transaction_methods
from django.core import mail
class TransactionTest(object):
def setUp(self):
transaction.enter_transaction_management()
transaction.managed(True)
disable_transaction_methods()
@thisboyiscrazy
thisboyiscrazy / owner_authorization.py
Last active December 15, 2015 18:39
Small Authorization class for tasypie. Allow Create, Read, Update, and Delete of users items.
class Authorization(object):
def auth_item(self,object_list,bundle):
return bundle.obj.user_id = request.user.id
def create_detail(self,object_list,bundle): return self.auth_item(object_list,bundle)
def read_detail(self,object_list,bundle): return self.auth_item(object_list,bundle)
def update_detail(self,object_list,bundle): return self.auth_item(object_list,bundle)
def delete_detail(self,object_list,bundle): return self.auth_item(object_list,bundle)
@thisboyiscrazy
thisboyiscrazy / angularjs-button-loading.js
Created March 11, 2013 21:10
Angularjs button loading like twitter bootstraps e.g. <button btn-loading="something.busy" data-loading="I'm working on it...">Do It</button>
angular.module('ui.bootstrap.buttons', [])
.directive('btnLoading',function () {
return {
link:function (scope, element, attrs) {
scope.$watch(
function () {
return scope.$eval(attrs.btnLoading);
},
function (value) {
@thisboyiscrazy
thisboyiscrazy / django-login-required-template-view.py
Created March 5, 2013 16:01
A TemplateView mixed with a Login Required view
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
class LoginRequiredMixin(object):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
class LoginRequiredTemplateView(LoginRequiredMixin,TemplateView):