Skip to content

Instantly share code, notes, and snippets.

@joshz
joshz / gist:742490
Created December 15, 2010 19:41
combine multiple files with filenames starting with capital letters
with open('dict.txt', 'w') as outfile:
for char in range(ord('A'), ord('Z')+1):
outfile.write(open('subdir/' + chr(char) + ' sdict.txt', 'r').read())
@joshz
joshz / remove_first_line_item.py
Created February 2, 2011 14:31
plugin for python script for notepad++, removes first line item, bet you could use a regex
from string import find
def testContents(contents, lineNumber, totalLines):
index = string.find(contents, " ")
if(index == -1):
editor.deleteLine(lineNumber)
return 0
else:
editor.replaceWholeLine(lineNumber, contents[index+1:])
@joshz
joshz / test.py
Created February 7, 2011 03:13
struct inheritance, polymorphism in c++
#include <iostream>
using namespace std;
struct CommonBase
{
public:
CommonBase();
CommonBase(int);
virtual ~CommonBase();
int getC(){return c;}
def fix_addresses():
"""
checks file that already only have multiple addresses
"""
print "reading input file"
input_file = open('inputfile.csv')
reader = csv.reader(input_file,
dialect='excel',
delimiter=',')
@joshz
joshz / FizzBuzz.py
Created May 20, 2011 19:33
FizzBuzz in Python
import cProfile
import pstats
def fizbuzz1():
for i in range(1, 101):
if (i % 3== 0) and (i % 5 == 0):
print('FizzBuzz')
elif i % 3 == 0:
print ('fizz')
elif i % 5 == 0:
@joshz
joshz / gist:997677
Created May 29, 2011 11:38
clean logs win 7
@echo off
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
echo.
echo goto theEnd
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
import java.util.Scanner;
import java.text.DecimalFormat;
public class Temperature
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
double celsius;
System.out.print("Enter a degree in Celsius: ");
@joshz
joshz / RestaurantReviewQueries.cs
Created June 10, 2011 20:37
OdeToFood Queries: FindTheBest, FindTheLatest - RestaurantReviewQueries
using System.Collections.Generic;
using OdeToFood.Models;
namespace OdeToFood.Queries
{
public static class RestaurantReviewQueries
{
//...
public static RestaurantReview FindTheBest(this IQueryable<RestaurantReview> reviews)
{
from collections import Counter
cnt = Counter("abracadabra")
print cnt
s = 'abracadabra'
d={}
for c in s:
d[c] = d.get(c, 0)+1
print d
@joshz
joshz / read(1).py
Created August 14, 2011 10:32
find string in file using just read(1)
import cProfile
import pstats
def meth():
check = 'abst'
c=1
r=1
location = (-1, -1)
with open("temp.txt", 'rb') as p:
ch = p.read(1)