Skip to content

Instantly share code, notes, and snippets.

@benwillkommen
benwillkommen / tests.py
Created February 20, 2016 18:50
gross or nah?
def test_put_detail_without_pk(self):
payload = self.dailytotal_post_data.copy()
payload['carbohydrate'] = 69
# I'd like to support PUT to create on detail resources.
# If there's no pk on the payload for a PUT, tastypie will create it.
# However, there needs to be a token for the pk for the route to match the resource detail route.
# How gross is throwing in a pk that cannot exist in the url, just to get the route to match?
# I haven't had to break out the tastypie source code yet today, and I kind of want to keep it that way
resp = self.api_client.put('/api/v1/dailytotal/-1/', format='json', data=payload)
@benwillkommen
benwillkommen / monitoringsuppressions.psm1
Last active February 23, 2016 17:29
ServiceNow lack-of-API hack script ¯\_(ツ)_/¯
function New-LogicalisMonitoringSuppression{
[cmdletbinding()]
Param(
[String[]]
[Parameter(Mandatory=$true)]
$Server,
$ShowBrowser = $False
)
begin{}
process{
@benwillkommen
benwillkommen / install-commerce-server-assemblies-into-gac.ps1
Last active August 29, 2015 14:16
install Commerce Server assemblies in GAC windows server 2012
Set-location "C:\Assemblies"
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$assemblyPaths = Get-ChildItem -recurse | select FullName | where { $_.FullName -like "*.dll" }
foreach ($assembly in $assemblyPaths)
{
$publish.GacInstall($assembly.FullName)
}
//the variable "oversimplifiedModule" gets assigned the return value of the anonymous and self executing function
var oversimplifiedModule = (function(){
//"private" variables are declared within the scope of the anonymous function: "counter" will not be in the global scope.
var counter = 42;
//the return value of the anonymous function can be considered the modules "public" interface
return {
incrementCounter: function(){
//because we refer to "counter", which is in the outer scope, inside this inner scope, a closure is formed, which keeps a reference to "counter"
//and prevents it from being garbage collected. closures are very neat and useful.
$.post( "/endpoint/url/goes/here",
{
message: "this is an object full of data that you're POST'ing to the server",
A: 69,
S: true,
L: "your dreams"
},
function( data ) {
console.log("we're in the success callback! everything is fine!");
console.log("here's what the server returned:", data);
<html>
<head>
<title>My Site!</title>
</head>
<body>
<img id="mainpicture" src="http://girldevelopit.com/assets/pink-logo.png">
<br/>
<a href="#" onclick="favoriteThings()">
Favorite Things
</a>
<html>
<head>
<title>My Site!</title>
<script src="myjavascriptfile.js"></script>
</head>
<body>
<a href = "#" onclick="calculate()">
Calculate life time supply
</a>
</body>
var myAge = 27;
var maxAge = 100;
var coffeePerDay = 2;
var lifetimeSupply = (maxAge - myAge) * coffeePerDay * 365;
if (lifetimeSupply > 40000){
alert("you drink too much coffee");
} else {
alert("you'll probably be fine");
var myAge = 27;
var maxAge = 100;
var coffeePerDay = 2;
var lifetimeSupply = (maxAge - myAge) * coffeePerDay * 365;
var message = "You will need " + lifetimeSupply + " cups of coffee to last until your old age of " + maxAge;
alert(message);
<html>
<head>
<title>My Site!</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="main.js"></script>
</head>
<body>
<div id="friendMessage"></div>
<a id="calculationLink" href="#" onclick="calculate()">dust calculation</a>
<a href="#" onclick="favoriteThings()">favorite things</a>