Skip to content

Instantly share code, notes, and snippets.

View hanleybrand's full-sized avatar

Peter Hanley hanleybrand

View GitHub Profile
@hanleybrand
hanleybrand / bb_bb60_expensive_queries.sql
Created April 23, 2015 20:09
Expensive queries ordered by CPU
/* Expensive queries ordered by CPU */
SELECT TOP 20
st.text,
--qp.query_plan,
qs.execution_count,
qs.total_worker_time AS Total_CPU,
total_CPU_inSeconds = --Converted from microseconds
qs.total_worker_time/1000000,
average_CPU_inSeconds = --Converted from microseconds
/* Blocking Report */
SELECT t1.resource_type AS [lock type], db_name(resource_databASe_id) AS[database],
t1.resource_ASsociated_entity_id AS [blk object],
t1.request_mode AS [lock req], --lock requested
t1.request_session_id AS [waiter sid], --spid of waiter
t2.wait_duration_ms AS [wait time(ms)],
(SELECT text FROM sys.dm_exec_requests AS r --get sql for waiter
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle)
WHERE r.session_id = t1.request_session_id) AS waiter_batch,
@hanleybrand
hanleybrand / step0b_id_insert_damn_you.sql
Last active August 29, 2015 14:18
Problem with step 0b (Case #02139497 - group assignment attempts are not viewable in this course)
-- I get
-- IDENTITY_INSERT is already ON for table 'bb_bb60.dbo.group_attempt_files_prv'. Cannot perform SET operation for table 'attempt_prv'
-- if I set it ON and
-- Cannot insert explicit value for identity column in table 'attempt_prv' when IDENTITY_INSERT is set to OFF.
SET IDENTITY_INSERT attempt_prv ON;
INSERT INTO attempt_prv
([GRADEBOOK_GRADE_PK1], [PK1], [QTI_RESULT_DATA_PK1], [LINKREFID], [SCORE],
[GRADE], [STUDENT_COMMENTS], [INSTRUCTOR_COMMENTS], [INSTRUCTOR_NOTES], [STATUS],
[ATTEMPT_DATE], [DATE_ADDED], [DATE_MODIFIED], [LATEST_IND], [comment_public_ind],
@hanleybrand
hanleybrand / ldap_bind_u.py
Last active August 29, 2015 14:18
python-ldap with bind user for django
import ldap
from django.conf import settings
ldap_auth = settings.LDAP_AUTH[0]
ldap_uri = ldap_auth['uri']
l_user = ldap_auth['bind_user']
l_pass = ldap_auth['bind_password']
searchScope = ldap_auth['scope']
base = ldap_auth['base']
@hanleybrand
hanleybrand / check_ya_select.sql
Created March 31, 2015 21:32
checking the select queries
use bb_bb60;
declare @COURSEID varchar(200)
declare @COURSEPK int
set @COURSEID = '111111111111'
set @COURSEPK = (select pk1 from course_main where course_id = '111111111111')
print @coursePK
SELECT *
@hanleybrand
hanleybrand / bb_step1-3.sql
Last active August 29, 2015 14:18
Blackboard Learn: Fix broken Group Assignments (T-SQL / bb_bb60)
/*
**Fix broken Group Assignments (T-SQL / bb_bb60)
assumes step_0 is complete and that tables
group_attempt_files_prv, attempt_prv and group_attempt_prv
exist. see https://gist.github.com/hanleybrand/8ef04daac0e960b4da14
*/
use bb_bb60;
declare @COURSEID varchar
set @COURSEID = '111111111111111' # replace with valid course id
@hanleybrand
hanleybrand / bb_step0.sql
Created March 31, 2015 21:21
Blackboard Learn - Group Assignments broken by editing groups; fix for MS SQL Server, bb_bb60 schema
/* Step 0 create preservation tables as a backup in case */
-- psql
--CREATE TABLE group_attempt_files_prv
-- AS (SELECT * FROM group_attempt_files WHERE 1=0);
-- tsql
SELECT gaf.* into group_attempt_files_prv
FROM group_attempt_files gaf WHERE 1=0;
@hanleybrand
hanleybrand / research_and_destroy.py
Last active August 29, 2015 14:17
oh the humor
def re_search():
and_dest = 'roy'
return True
# or even
def re_search():
return 'and_destroy'
@hanleybrand
hanleybrand / simple_django_fake_distinct.py
Last active August 29, 2015 14:17
A simple function that will do a fake distinct on a django model; Why? Well, filter.distinct() apparently doesn't work with mysql because #$%#@$%#
def fake_distinct_for_model_field_values(dj_model, field_name):
"""
Perform a fake distinct query on the value_list of a model's objects
example: from myapp.models import ActivityLog
import fake_distinct_for_model_field_values as fake_dist
fake_dist(ActivityLog, 'event_types')
>>> [u'login', u'media-download', u'media-thumbnail', u'media-download-image']
"""
output = set()
for x in dj_model.objects.values_list(field_name):
@hanleybrand
hanleybrand / shell_plus output.md
Last active August 29, 2015 14:17
shell plus output of an issue with rooibos.access.functions
from django.contrib.auth.models import AnonymousUser
from rooibos.storage.models import Storage
from rooibos.access.functions import filter_by_access
u = User.objects.get(pk=1)
au = AnonymousUser()
q = Storage
qo = Storage.objects.all()