Skip to content

Instantly share code, notes, and snippets.

@them0nk
them0nk / loganalyser.py
Created December 13, 2012 10:58
Sample ninja ide plugin
# -*- coding: UTF-8 -*-
#===============================================================================
# IMPORTS
#===============================================================================
import os
import json
import datetime
import string
import socket
@them0nk
them0nk / __youtube-dl.sh
Created May 13, 2012 02:03
Simple Autocompletion for youtube-dl
__youtube-dl()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts="-h --help --version -U --update -i --ignore-errors -r --rate-limit -R --retries --dump-user-agent --list-extractors --playlist-start --playlist-end --match-title --reject-title --max-downloads -t --title -l --literal -A --auto-number -o --output -a --batch-file -w --no-overwrites -c --continue --no-continue --cookies --no-part --no-mtime --write-description --write-info-json -q --quiet -s --simulate --skip-download -g --get-url -e --get-title --get-thumbnail --get-description --get-filename --get-format --no-progress --console-title -v --verbose -f --format --all-formats --prefer-free-formats --max-quality -F --list-formats --write-srt --srt-lang -u --username -p --password -n --netrc --extract-audio --audio-format --audio-quality -k --keep-video"
if [[ ${cur} == * ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
@them0nk
them0nk / minesweeper.java
Created April 30, 2012 01:45
Minesweeper: PC/UVa IDs: 110102/10189
/*
* Main.java
* java program model for www.programming-challenges.com
*/
import java.io.*;
import java.util.*;
class minesweeper implements Runnable{
@them0nk
them0nk / race.java
Created April 30, 2012 01:44
The Race: PC/UVa IDs: 110103/10137
/*
* Main.java
* java program model for www.programming-challenges.com
*/
import java.io.*;
import java.util.*;
class Main implements Runnable{
@them0nk
them0nk / hailstorm.java
Created April 30, 2012 01:42
3n+1 Problem: PC/UVa IDs: 110101/100
/*
* Main.java
* java program model for www.programming-challenges.com
*/
import java.io.*;
import java.util.*;
class hailstorm implements Runnable{
@them0nk
them0nk / heapds.rb
Created April 26, 2012 02:06
heap datastruture
class Heap
def initialize arr, type=:min
@heap = arr
self.class.class_eval { alias_method "get#{type.to_s}", :getroot }
if type == :min
@op = :<
else
@op = :>
end
@them0nk
them0nk / two_sum.rb
Created April 26, 2012 01:59
Given an array find the combination of two numbers in the array which makes the given sum
require 'set'
def twosum arr,sum_arr
a = Set.new(arr)
sum_arr.each do |sum|
count = 0
arr.each do |elem|
puts("#{sum} = #{elem} + #{sum-elem}") if a.include? (sum-elem)
end
@them0nk
them0nk / search_rot.rb
Created April 26, 2012 01:54
Search in a sorted, rotated list. Given a sorted list of N integers that has been rotated an unknown number of positions, e.g., 15 36 1 7 12 13 14, design an O(log N) algorithm to determine if a given integer is in the list.
def search_arr arr,val
darr = arr+arr
sz = arr.size
start_loc = 0
end_loc = sz - 1
mid_loc = (end_loc - start_loc)/2
while start_loc < end_loc
@them0nk
them0nk / nthsmallest.rb
Created April 26, 2012 01:52
Nth smallest number in an unsorted array
def nthsmallest arr,startpos,endpos,nth
def choose_pivot arr,startpos,endpos
#THis is for selecting median of three , you can return a random number as well.
if ((arr[startpos] < arr[endpos]) and (arr[startpos] > arr[startpos+ (endpos-startpos)/2])) or ((arr[startpos] > arr[endpos]) and (arr[startpos] < arr[startpos+ (endpos-startpos)/2]))
return startpos
elsif ((arr[endpos] < arr[startpos]) and (arr[endpos] > arr[startpos+ (endpos-startpos)/2])) or ((arr[endpos] > arr[startpos]) and (arr[endpos] < arr[startpos+ (endpos-startpos)/2]))
return endpos
@them0nk
them0nk / second_smallest.rb
Created April 26, 2012 01:50
second smallest number in an array
def second_smallest arr
min_arr = []
arr.each_slice(2) do |x,y|
if y.nil? or x < y
min_arr << x
else
min_arr << y
end