Skip to content

Instantly share code, notes, and snippets.

View garyherd's full-sized avatar

Gary Herd garyherd

View GitHub Profile
@garyherd
garyherd / SQLServerWithDataReader.cs
Created October 31, 2013 03:33
snippet to retrieve data while connected to SQL Server. Uses the SqlDataReader object.
using System.Data.SqlClient;
//Step 1: Handshake with the database
SqlConnection myConnection = new SqlConnection(connection string);
myConnection.Open();
//Step2: Specify the command
SqlCommand myCommand = myConnection.CreateCommand();
@garyherd
garyherd / SQLDataSetStronglyTyped.cs
Last active December 27, 2015 06:29
SQL Server with Data Sets & Data Adapters (i.e. Disconnected mode)
//No connection of Connection string creation
//No DataAdapter configuration
//Automatically generates an adapter specifically for working with OUR tables.
//ex.
CustomerDataSetTableAdapters.CustomersTableAdapter cta = new CustomerDataSetTableAdapter;
CustomerDataSet ds = new CustomerDataSet();
@garyherd
garyherd / gist:1c11c242d2c8e0d9c413
Created February 13, 2015 16:16
Sort Dictionary By Value Using Lambda
sample_dict = {'Four': 4, 'Three': 3, 'Five': 5, 'Two': 2}
sample_dict_sorted_list = sorted(sample_dict.items(), key=lambda x : x[1])
for item in sample_dict_sorted_list:
print item
@garyherd
garyherd / gist:b717dc19f89e0bd4445f
Created February 13, 2015 16:19
Return Ranks From A List
def ranks(scores):
result = []
sorted_list = sorted(scores, reverse=True)
for score in scores:
rank = sorted_list.index(score) + 1 # index() returns the lowest index in list that obj appears.
result.append(rank)
return result
@garyherd
garyherd / gist:c7ff20aafe9d6a18ab01
Created February 26, 2015 06:00
Flipping bits for unsigned integers
def flipping_bits(a):
# in this case, it flips a 32-bit unsigned int
return ~a & 0xFFFFFFFF
n = int(raw_input()) #faster than n = input() , since input() executes the line as python command
res = []
for i in range(0,n):
a = int(raw_input())
res.append(flipping_bits(a))
import datetime
class Person(object):
def __init__(self, name):
"""create a person called name"""
self.name = name
self.birthday = None
self.lastName = name.split(' ')[-1]
def getLastName(self):
@garyherd
garyherd / simple_caesar_encryption.py
Created March 2, 2016 04:03
Demonstrates Python class inheritance with a simple encryption algorithm
import string
### DO NOT MODIFY THIS FUNCTION ###
def load_words(file_name):
'''
file_name (string): the name of the file containing
the list of words to load
Returns: a list of valid words. Words are strings of lowercase letters.
function palindrome(str) {
var re = /[a-zA-Z0-9]/;
var stripped_str_arr = [];
for (var letter in str) {
if (str[letter].match(re)) {
stripped_str_arr.push(str[letter].toLowerCase());
}
}
var rev_array = stripped_str_arr.slice().reverse();
var rev_str = rev_array.join("");
@garyherd
garyherd / config.json
Created October 28, 2016 14:27 — forked from anonymous/config.json
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",