Skip to content

Instantly share code, notes, and snippets.

View kjlape's full-sized avatar
🤝
nice to meet you

Kaleb Lape kjlape

🤝
nice to meet you
View GitHub Profile
@kjlape
kjlape / snoop.js
Created April 29, 2015 16:56
Snoop on values in js...
function snoop(/*args*/) {
console.log.apply(console, Array.prototype.slice.call(arguments))
return arguments[0]
}
@kjlape
kjlape / CryptoRando.js
Last active August 29, 2015 14:20
Crypto/Rando js stuff... Now isomorphic!
if (typeof crypto === 'undefined' || crypto == null) crypto = require('crypto')
var _MAX_CRYPTO_BYTES = 65536
var _BYTES_IN_UINT32 = 4
var _MAX_CRYPTO_UINT32 = Math.floor(_MAX_CRYPTO_BYTES / _BYTES_IN_UINT32)
if (!crypto.getRandomValues)
crypto.getRandomValues = function (buffer) {
var randomBytes = crypto.randomBytes(buffer.buffer.byteLength)
@kjlape
kjlape / playground.js
Last active August 29, 2015 14:18
My animated Isomer playground. (http://jdan.github.io/isomer/playground)
var Point = Isomer.Point
var Path = Isomer.Path
var Shape = Isomer.Shape
var Vector = Isomer.Vector
var Color = Isomer.Color
var rotationDuration = 2 * 1000
var canvas = document.getElementById("canvas")
Math.TwoPI = Math.PI * 2
@kjlape
kjlape / reverse.js
Last active August 29, 2015 14:15
Recursive and iterative string reversal in JS... Cuz work is boring.
var reverse = function(str) {
str = str.split('')
var end = str.length - 1
for (var i = 0; i + 1 <= end - i; ++i) {
var t = str[i]
str[i] = str[end - i]
str[end - i] = t
}
return str.join('')
@kjlape
kjlape / bad.cs
Last active August 29, 2015 14:15
Example of refactoring at work.
// 0)
private void UpdateErrorResponseLog(CommandResponseElement[] array, long id)
{
//Logging all errors and response messages returned to TOA_InboundAPI_Response_Errors table
try{
foreach (CommandResponseElement value in array)
@kjlape
kjlape / get_current_domain.cs
Created January 28, 2015 13:51
ASP.NET get current domain.
// http://stackoverflow.com/questions/61817/whats-the-best-method-in-asp-net-to-obtain-the-current-domain
Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port)
@kjlape
kjlape / ugly_js_hack.html
Last active August 29, 2015 14:13
*deep breath* This is a silly hack to workaround even sillier dynamically generated server-side Telerik ImageButton junk for a temporary service outage. This is how you know you've truly sold out to The Man as a software developer.
<script type="text/javascript">
(function($) {
$(document).ready(function() {
$("#ctl00_MasterBody_MyPhoneNumbers1_RadGrid1_ctl00_ctl04_imgbtnVoicemail")
.attr("id", "anti_telerik_hack" + Math.random())
.attr("name", "anti_telerik_hack" + Math.random())
.off()
.click(function() { alert("Pardon the Interruption. The service you are looking for is unavailable at the moment. We will be back up on January 20, so please call 1-855-287-5969 for assistance with your Voicemail changes. Thank you for your patience."); return false; });
});
})($telerik.$);
@kjlape
kjlape / ChickenUtil.hs
Last active August 29, 2015 14:10
Chicken utilities for Haskell.
import qualified Data.Char as Char
import Data.List
capitalized :: String -> String
capitalized "" = ""
capitalized (head:tail) = Char.toUpper head : tail
trimmer :: ([a] -> a) -> ([a] -> [a]) -> (a -> Bool) -> [a] -> [a]
trimmer _ _ _ [] = []
trimmer next rest pred l
@kjlape
kjlape / GetProperty.sql
Last active August 29, 2015 14:10
Script to get properties out of ASP.NET Profile Property Key Value data based on the key.
begin
-- These first three would be the function arguments.
declare @property_name nvarchar(32) = 'CurrentAcct'
declare @prop_encoding nvarchar(64) = 'CurrentTN:S:0:10:CurrentSite:S:10:3:CurrentAcct:S:13:8:' --'CurrentSite:S:0:3:CurrentAcct:S:3:8:'
declare @properties nvarchar(32) = '501463909143229127406' --'43731870303'
declare @propval_index bigint = PATINDEX('%' + @property_name + ':%', @prop_encoding) + LEN(@property_name) + 1
declare @propval_start_index bigint = CHARINDEX(':', @prop_encoding, @propval_index) + 1
declare @propval_start_index_len bigint = CHARINDEX(':', @prop_encoding, @propval_start_index) - @propval_start_index
declare @propval_len_index bigint = @propval_start_index + @propval_start_index_len + 1
@kjlape
kjlape / mssql.coffee
Last active August 29, 2015 14:09
Wrap mssql npm package for meteor.
NodeSql = Npm.require 'mssql'
Connection = NodeSql.Connection
Request = NodeSql.Request
Transaction = NodeSql.Transaction
wrapProtoFunc = (klass, name) ->
Meteor.wrapAsync klass.prototype[name]
class wRequest extends Request