Skip to content

Instantly share code, notes, and snippets.

@kmark
kmark / LogMeIn.php
Last active July 16, 2023 06:31
PHP implementation of cPanel's Perl LogMeIn class.
<?php
namespace cPanel;
/**************************************************************************************
* Copyright (c) 2013, cPanel, Inc. *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, *
* are permitted provided that the following conditions are met: *
* *
@kmark
kmark / plexDownload.php
Last active April 6, 2022 23:46
The Plex Universal Transcoder Downloader mimics the actions of the Plex/Web media flash player to download transcoded media. The differences begin when the downloader saves the streamed data and pieces it together. First a start.m3u8 playlist file is requested from the server with a query string that defines the transcoding options. Inside the …
<?php
/*******************************************************************************
* Plex Universal Transcoder Downloader v1.3 *
* See --help or --usage for more info *
*******************************************************************************
* Copyright 2013 Kevin Mark *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
@kmark
kmark / TabsAdapter.java
Created September 3, 2013 00:42
An extensible FragmentPagerAdapter that supports both FragmentActivity and Fragment hosts.
package you.should.change.this;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
@kmark
kmark / plexDownloadMulti.sh
Created September 24, 2013 01:12
Super simple bash script to repeatedly execute plexDownload.php with the same encoding settings but different media IDs. Great for TV show seasons.
#!/bin/bash
# Copyright 2013 Kevin Mark
# Licensed under the Apache License, Version 2.0
# Will expand upon this script to be more convient, proof of concept right now.
# EXAMPLE USAGE: ./plexDownloadMulti.sh "-h 127.0.0.1:32400 -r 720x480 -b 800" 123 456 789
# Universal encoding settings in quotes is the first param. Space-seperated mediaIds are the rest
# Change the "folderformedia" and make sure it exists. Change the extension too if you want.
@kmark
kmark / findLowQualitySongs.php
Last active January 20, 2017 08:22
Finds low quality songs in a directory based on a minimum bit rate. Tested with PHP 5.5.4. Find MediaInfo at mediaarea.net. I don't rely on MediaInfo for the recursion because it uses a fuckton of memory trying to do it.
<?php
/*******************************************************************************
* Copyright 2013 Kevin Mark *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
@kmark
kmark / CMPLXZRO
Created May 20, 2014 06:00
I couldn't remember how to solve for complex roots/zeroes of a polynomial during a test so I whipped up this quick TI-84 program to brute-force the answer. The input function must use the X variable.
a+b
Input "MAX=",M
Input "FUNC=",Str0
For(I,1,M)
I→X
expr(Str0)→R
If real(R)=0 and imag(R)=0
Disp X,conj(X)
End
/*******************************************************************************
* Copyright © 2014 Kevin Mark *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
@kmark
kmark / de64.php
Created August 15, 2014 21:14
Recursively removes the base64 "encryption" on some obfuscated PHP files. First and only CLI parameter is the path to the encoded file.
<?php
/* Works on targets that are in this format:
* <?php $FirstVar = 'base64here'; $SecondVar = '$ThirdVar = base64_decode($FirstVar); eval($ThirdVar);'; eval($SecondVar); ?>
* Where the result of the base64_decode is more PHP that follows the above format.
*/
$target = $argc < 2 ? "" : $argv[1];
if($target === "" || !file_exists($target)) {
@kmark
kmark / AndroidClasspath.java
Last active January 14, 2024 13:41
Explores the current Android classpath
try {
PathClassLoader pcl = (PathClassLoader) Thread.currentThread().getContextClassLoader();
Field f = Class.forName("dalvik.system.BaseDexClassLoader").getDeclaredField("pathList");
f.setAccessible(true);
Object dpl = f.get(pcl);
Class cls = Class.forName("dalvik.system.DexPathList");
Field f2 = cls.getDeclaredField("dexElements");
f2.setAccessible(true);
Object[] elements = (Object[])f2.get(dpl);
for(Object e : elements) {
@kmark
kmark / LCM.c
Created November 16, 2014 20:49
Least common multiple calculator via greatest common denominator using Euclid's method. Includes both iterative and recursive implementations.
int gcdIterative(int a, int b) {
while(true) {
if(a > b) {
a -= b;
continue;
}
if(b > a) {
b -= a;
continue;
}