Skip to content

Instantly share code, notes, and snippets.

View CodyKochmann's full-sized avatar

Cody Kochmann CodyKochmann

  • Severn, MD
View GitHub Profile
@CodyKochmann
CodyKochmann / findall.py
Created May 14, 2015 17:10
searches a string for a substring and returns an array of indexes
def findall(search_field,search):
# searches a string for a substring and returns an array of indexes
# by: Cody Kochmann
tmp_field = search_field.split(search)
if len(tmp_field) == 1:
return(False)
output = []
tmp_string = ""
for i in range(len(tmp_field)):
tmp_string += tmp_field.pop(0)
@CodyKochmann
CodyKochmann / get-str-between.md
Last active June 22, 2017 20:03
This python snippet gets a substring between two strings in a string.

This python snippet gets a substring between two strings in a string. For example, get_str_between(html_code,'/*','*/') would return the first boxed javascript snippet that it could find.

There's also get_every_str_between() which returns an array of every substring that is found between those two patterns in the given text.

def get_every_str_between(s, before, after):
  """ returns an array of substrings between "before" and "after"
      by: Cody Kochmann """
  return (i.split(after)[0] for i in s.split(before)[1:] if after in i)
@CodyKochmann
CodyKochmann / get_complete_string.py
Created May 15, 2015 04:42
returns a substring starting with start and ending with end
def get_complete_string(s,start,end):
# returns a substring starting with start and ending with end
# By: Cody Kochmann
unique="~~~~the~obvious~way~to~do~it~~~~"
return(start+s.replace(start, unique).replace(end, unique).split(unique)[1]+end)
@CodyKochmann
CodyKochmann / random_string.py
Created May 15, 2015 23:34
Generates a random string with selectable characters
def random_string(length=32,upper=True,lower=True,digits=True):
# Generates a random string with selectable characters
# By: Cody Kochmann
from random import choice
chars = ""
if upper:
chars+="QWERTYUIOPASDFGHJKLZXCVBNM"
if lower:
chars+="qwertyuiopasdfghjklzxcvbnm"
if digits:
@CodyKochmann
CodyKochmann / generate_duplicate_name.py
Created May 17, 2015 06:51
python snipet that allows duplicate file generation
def generate_duplicate_name(f_name,output_path):
## snipet that allows duplicate file generation if need be
# by: Cody Kochmann
from os import listdir
if f_name in listdir(output_path):
if allow_duplicates == False:
v_print(f_name+" already downloaded")
return(False)
else:
placeholder_name=2
@CodyKochmann
CodyKochmann / pct_of_smaller_side.js
Created May 20, 2015 00:37
sizes a dom element to the smaller sized side
var pct_of_smaller_side = function(dom_e,selected_percent){
// sizes a dom element to the smaller sized side
var width = $(window).width();
var height = $(window).height();
var important_measurement=0;
if (width>height){
important_measurement=height*selected_percent;
} else {
important_measurement=width*selected_percent;
}
@CodyKochmann
CodyKochmann / set_view.js
Created May 20, 2015 00:46
sets horizontal or vertical view rules of a dom element
var set_view = function(dom_e){
// sets horizontal or vertical view rules of a dom element
// by: Cody Kochmann
var width = $(window).width();
var height = $(window).height();
var horizontal=width>height;
var vertical=!horizontal;
if (horizontal){
if(dom_e.hasClass('horizontal')==false){
dom_e.addClass('horizontal');
@CodyKochmann
CodyKochmann / gen_test_string.coffee
Last active August 25, 2016 17:58
generates a random string to test against
gen_test_string = (len) ->
# generates a random string to test against
test = 'ab cd efg hij klm nop qrs tuvwx yzA B CD EFG HIJ KLM NOPQ RSTUV WXY Z 123 4567 8 90'
i = 0
while i < len
test += test.charAt(Math.floor(Math.random() * test.length))
i++
return
@CodyKochmann
CodyKochmann / timed_interval.coffee
Created June 12, 2015 17:00
An improved setInterval function with pausing and no overlapping of intervals.
window.timed_interval = (@main_process, @timeout, @verbose=true) ->
`/*
Author: Cody Kochmann
Build: 4
Date Last Modified: Fri Jun 12 09:53:37 PDT 2015
This is an improved function to the currently used setInterval in javascript.
It has better Controls towards the control flow of the interval overall.
This implementation also prevents function overlapping where is the interval
is set too quickly and tries to run again before the previous
/(https?|ftp)://([0-9]|\.|[a-z]|[A-Z]|_|/|,|=|\?){5,}\.mp4/g

I find this regex snippet useful when I'm throwing together a video link search algorithm or a video downloader for an app. This does nicely when looking for a link that works nicely with the chromecast.