Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am aweigold on github.
  • I am weigold (https://keybase.io/weigold) on keybase.
  • I have a public key ASAb_1RI8NanhU7ECEJ9Y9Y4aqdosflDQqoFBBUGa2idDgo

To claim this, I am signing this object:

@aweigold
aweigold / change-window-location-on-error-page-ui-router-state-change.js
Created October 16, 2016 22:19
Listens to ui-router for state changes and changes the window location if the current page is an error page.
$rootScope.$on('$stateChangeStart', function(evt, to, params){
var isError = $windowProvider.$get().document.querySelector("meta[name='yourErrorPageTag']");
if (isError) {
evt.preventDefault();
$windowProvider.$get().location = "/apppath/index.html" + $windowProvider.$get().location.hash;
}
});
@aweigold
aweigold / base-fragement-for-error-pages.html
Created October 16, 2016 22:14
base.html fragment file for supporting error pages.
<meta name="yourErrorPageTag" content="true" />
<base href="/apppath/" />
@aweigold
aweigold / grunt-templtated-index-with-errorpages-base.html
Created October 16, 2016 22:10
Templated index.html file for supporting error pages.
<!-- build:include:error404,error404 error/base.html --><!-- /build-->
@aweigold
aweigold / grunt-templtated-index-with-errorpages.html
Created October 16, 2016 22:03
Templated index.html file for supporting error pages.
<div class="page-container">
<div class="site-content">
<!-- build:remove:error400,error404 -->
<div ui-view="mainBody"></div>
<!-- /build -->
<!-- build:include:error400 error/400.html --><!-- /build-->
<!-- build:include:error404 error/404.html --><!-- /build-->
</div>
</div>
@aweigold
aweigold / grunt-processhtml-errorpage-targets.js
Created October 16, 2016 21:59
Grunt processhtml errorpage targets example
// 'paths' is setup earlier in my grunt file
processhtml: {
mainapp: {
options: {
strip: true,
data: {
year: new Date().getFullYear(),
localCssPath: paths.minCssName,
localJsPath: paths.minJsName
}
@aweigold
aweigold / BinaryChecksum.groovy
Created October 24, 2013 20:07
SQL BINARY_CHECKSUM implementation in Groovy See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=70832 for more information
long sum = 0
byte overflow;
String text = 'mystring'
for (int i =0; i< text.length(); i++){
sum = (long)((16* sum) ^ text.getBytes()[i])
overflow = (byte) (sum / 4294967296)
sum = sum - overflow * 4294967296
sum = sum ^ overflow
}
if (sum > 2147483647) {
@aweigold
aweigold / build.gradle
Last active December 20, 2015 23:38
Running custom builds for IntelliJ JUnit runner http://www.adamweigold.com/2013/08/intellij-idea-junit-running-and-non.html IntelliJ Idea provides some really awesome JUnit runners that allow you to right click test methods, classes, and packages, and quickly run/debug them. The default JUnit configuration runs Idea's "Make" prior to running you…
apply plugin: 'idea'
idea {
project {
ipr.withXml {
// Create a task to run gradle testClasses, which we will subsequiently bind to Default JUnit runner to
def runConfigComp = it.node.appendNode('component')
def runOpts = [
"default": "false",
"name": "testClasses for JUnit",
@aweigold
aweigold / Export DB to CSV with BCP.sql
Last active December 20, 2015 23:29
Exporting all tables to CSV in SQL Serverhttp://www.adamweigold.com/2011/11/exporting-all-tables-to-csv-in-sql.htmlThe following script will output a list of statements to use bcp to export all tables to CSV. To use another format, see the bcp documentation.
USE myDatabase
SELECT 'exec master..xp_cmdshell'
+ ' '''
+ 'bcp'
+ ' ' + TABLE_CATALOG + '.' + TABLE_SCHEMA + '.' + TABLE_NAME
+ ' out'
+ ' E:\releasedDB\prod\'
+ TABLE_CATALOG + '.' + TABLE_SCHEMA + '.' + TABLE_NAME + '.csv'
+ ' -c'
+ ' -t,'
@aweigold
aweigold / drop MS SQL Server DB.sql
Last active December 20, 2015 23:29
Deleting a database remotely with SQL Serverhttp://www.adamweigold.com/2011/11/deleting-database-remotely-with-sql.htmlThis should never be done on a production server, as it will open up security risks. This is useful for integration tests and utilities. Replace %dbName% appropriately
BEGIN
IF EXISTS (SELECT * FROM tempdb.sys.tables WHERE name LIKE '#dbFiles%')
DROP TABLE #dbFiles
END
EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE