Skip to content

Instantly share code, notes, and snippets.

View justingarrick's full-sized avatar

Justin Garrick justingarrick

View GitHub Profile
@justingarrick
justingarrick / fix.txt
Last active August 29, 2015 13:57
Fix Fatal Signal 11 when Google Analytics/Picasso is used with Retrofit/OkHttp
Create a method like the following:
/**
* Fix https://github.com/square/okhttp/issues/184
*
* @return an unfucked OkHttpClient for use with a RestAdapter
*/
public static OkClient createClient() {
OkHttpClient client = new OkHttpClient();
SSLContext sslContext;
@justingarrick
justingarrick / remotedata.sql
Last active October 4, 2015 05:48
Find Data Directory of Remote SQL Server Instance
SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1)
FROM master.sys.master_files
WHERE database_id = 1 AND file_id = 1
@justingarrick
justingarrick / sqllocks.sql
Last active October 4, 2015 05:48
Kill Stubborn SQL Server DB Locks
SELECT L.request_session_id AS SPID,
DB_NAME(L.resource_database_id) AS DatabaseName,
O.Name AS LockedObjectName,
P.object_id AS LockedObjectId,
L.resource_type AS LockedResource,
L.request_mode AS LockType,
ST.text AS SqlStatementText,
ES.login_name AS LoginName,
ES.host_name AS HostName,
TST.is_user_transaction as IsUserTransaction,
@justingarrick
justingarrick / pppoe.sh
Last active October 4, 2015 05:57
PPPoE DSL Modem Passthrough with Tomato
# Assuming modem is a Motorola 2210-02-1006 running in bridge mode w/ a LAN IP of 192.168.1.254
# Router is WRT54G running Tomato w/ LAN IP of 192.168.2.1 and is handling PPPoE
# In order to access modem's web UI via LAN:
# 1) Add the following script under Administration > Scripts > Init:
sleep 5
ip addr add 192.168.1.2/24 dev vlan1 brd +
iptables -I POSTROUTING -t nat -o vlan1 -d 192.168.1.0/24 -j MASQUERADE
# 2) Add the following script under Administration > Scripts > Firewall:
iptables -I POSTROUTING -t nat -o vlan1 -d 192.168.1.0/24 -j MASQUERADE
@justingarrick
justingarrick / youtube.sh
Last active October 4, 2015 05:57
Youtube Bookmarks -> MP3
# !/bin/bash
# Justin Garrick
# Put this script in a folder with get_flash_videos (http://code.google.com/p/get-flash-videos/)
# and your bookmarks.html file and run it
# This does no error checking/handling -- if a video cannot be found, it just won't be grabbed
# Grabs the urls from all bookmarks containing youtube in the url
for URL in `grep -i "<a href=.*youtube.*" bookmarks.html | cut -d '"' -f 2`; do
echo "Downloading ${URL}..."
# Download video as high quality mp4 if possible
@justingarrick
justingarrick / Demangle Swift.py
Created October 5, 2015 13:20 — forked from steventroughtonsmith/Demangle Swift.py
Hopper Swift demangler
import subprocess
def looksLikeBeginning(doc,seg,adr):
if doc.is64Bits() and seg.readByte(adr) == 0x55 and seg.readByte(adr + 1) == 0x48 and seg.readByte(adr + 2) == 0x89 and seg.readByte(adr + 3) == 0xE5:
return True
if not doc.is64Bits() and seg.readByte(adr) == 0x55 and seg.readByte(adr + 1) == 0x89 and seg.readByte(adr + 2) == 0xE5:
return True
return False
doc = Document.getCurrentDocument()
@justingarrick
justingarrick / d2dreamstack.au3
Last active December 12, 2015 03:58
AutoIt3 script for aura stacking a paladin in D2. No idea if this still works, archiving it here.
HotKeySet("{DEL}", "stop")
Opt("MouseCoordMode", 0)
$i = 0
$i2 = 0
WinActivate("Diablo II")
WinWaitActive("Diablo II")
Do
$i = $i + 1
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using MyProject.Domain;
using EO.Pdf;
using EO.Pdf.Acm;
@justingarrick
justingarrick / generic_create.sql
Last active December 20, 2015 08:59
Generic SQL Server "create DB" script that uses the same defaults as "New Database" in SSMS. Locates data directory based on master.mdf.
USE [master]
DECLARE @dbName NVARCHAR(MAX)
SET @dbName ='Derp' -- Your DB name here
DECLARE @sql NVARCHAR(MAX)
DECLARE @template NVARCHAR(MAX)
DECLARE @dataDir NVARCHAR(MAX)
SET @dataDir = (SELECT SUBSTRING(physical_name, 1, CHARINDEX(N'master.mdf', LOWER(physical_name)) - 1) FROM master.sys.master_files WHERE database_id = 1 AND file_id = 1)
@justingarrick
justingarrick / WebAPIRawJSON.cs
Last active December 21, 2015 17:49
Read raw JSON in a WebAPI method that uses model binding
//Add
//Request.Content.ReadAsStreamAsync().ContinueWith(t => t.Result.Seek(0, SeekOrigin.Begin)).Wait();
//to your POST method, e.g.
[AntiForgeryToken]
public WeldProjectInfo Post([FromBody]RequestDetail details)
{
try
{
Request.Content.ReadAsStreamAsync().ContinueWith(t => t.Result.Seek(0, SeekOrigin.Begin)).Wait();