Skip to content

Instantly share code, notes, and snippets.

@clsnyder
clsnyder / reclaimWindows10.ps1
Created January 8, 2017 16:02 — forked from alirobe/reclaimWindows10.ps1
"Reclaim Windows 10" turns off a bunch of unnecessary Windows 10 telemetery, removes bloatware, and privacy invasions. Review and tweak before running. Scripts for reversing are included and commented. Fork via https://github.com/Disassembler0 (different defaults)
##########
# Win10 Initial Setup Script
# Author: Disassembler <disassembler@dasm.cz>
# Version: 1.7, 2016-08-15
# dasm's script: https://github.com/Disassembler0/Win10-Initial-Setup-Script/
# THIS IS A PERSONALIZED VERSION
# This script leaves more MS defaults on, including MS security features.
# Tweaked based on personal preferences for @alirobe 2016-11-16 - v1.7.1
@clsnyder
clsnyder / authenticate.php
Created December 18, 2016 23:03
Login script to put at top of php files
<?php
// Execute common code to connection to the database and start the session
require("../Login/common.php");
if(empty($_SESSION['user']))
{
// If they are not, we redirect them to the login page.
header("Location: ../Login/login.php");
// Without the die statement, people can view your members-only content without logging in.
die("Redirecting to login.php");
}
@clsnyder
clsnyder / get_json.php
Created March 2, 2015 00:58
PHP from Json
//assign the file contents to the array myJsonInput
$myJsonInput = file_get_contents("/Path/test.json");
//Use json_decode to "Take a JSON encoded string and convert it into a PHP variable"
$json_arr=json_decode($myJsonInput,true);
//Create an empty array, $myLinks, to put the links in (in this example of pinboard bookmarks)
$mylinks = array();
The test.json file is of the form:
@clsnyder
clsnyder / create_google_map.rb
Created March 2, 2015 00:30
Create a google map from csv and xml data with ruby
require ‘csv’ mydata = [] zips = File.open(‘zips.txt’) do |io|
h = {}
io.eachline do |line|
zip, freq = CSV.parseline line
h[zip]=freq
end
h
end
File.open(“target.xml”,“w”) do |target| File.open(‘ZIP_CODES.txt’) do |io|
io.eachline do |line|
@clsnyder
clsnyder / google_stocks.py
Created February 19, 2015 02:56
Python - Google stock quotes
import urllib
import re
def get_quote(symbol):
base_url = 'http://finance.google.com/finance?q='
content = urllib.urlopen(base_url + symbol).read()
m = re.search('class="pr".*?>(.*?)<', content)
if m:
quote = m.group(1)
print symbol + " " + quote
@clsnyder
clsnyder / Intro_to_R.r
Created February 14, 2015 22:36
R statistics - basic data analysis with automation
R statistics - basic data analysis with automation
To read in excel files
library ( gdata )
# Note the forward slash on windows
# Set the working directory
setwd("C:/Documents and Settings/csnyder/Desktop/My Dropbox/Projects/NEC/Data/")
# Check it
(WD #mdat # mdat # Attach it if you wish
@clsnyder
clsnyder / CSV_Sum_by_Col.rb
Created February 14, 2015 21:54
Ruby CSV sum by column
# This takes csv data, and identifies it by column header (bob), sums the x column, and then adds a column with x/sum x
require ‘rubygems’
require ‘fastercsv’
csv="f,bob\na,0\nb,1\nc,2\nd,3\n"
table = FCSV.parse(csv, :headers => true, :converters => :integer)
xs = table['bob'].map{|x| x.to_i}
sum = Float table['bob'].inject{|sum,i| sum += i}
norm = xs.map{|x| x / sum}
table['n'] = norm
@clsnyder
clsnyder / jumble.py
Created February 14, 2015 16:37
Word Jumble solutions with python
#!/bin/env python
def find_jumble(jumble, word_file='/users/charleslsnyder/dictionary.txt'):
#you have to reset the word file to your dictionary and path
sorted_jumble = sort_chars(jumble)
for dictword in open(word_file, 'r').xreadlines():
if sorted_jumble == sort_chars(dictword):
yield dictword
def sort_chars(word):
w = list(word.strip().lower())
@clsnyder
clsnyder / beer.py
Created January 12, 2015 17:23
Get and analyze beer data
#!/usr/bin/python
# here is the link for the data: http://www.brewerydb.com/
from bs4 import BeautifulSoup
# Start making the soup
soup = BeautifulSoup(open('/Users/weatherh/Documents/beerStyles.xml'), "lxml")
# Walk through each element in the XML by first using FindAll. Then we need to change their
# names and fix some nesting
head_tag = soup.root
@clsnyder
clsnyder / R-UniqueFreqCounts.r
Created January 7, 2015 02:22
R-Get Frequency count for unique values of a column
# Frequency count:
library(data.table)
dt = as.data.table(ops)
y <- dcast.data.table(dt[, bla := "count"], opCode ~ bla, drop=FALSE, fun.agg=length)
freq_ct_ops <- y[order(-y$count),]
View(freq_ct_ops)
# Now get the top 5%
freq_ct_ops[ , tail( .SD , ceiling( nrow(.SD) * .05 ) ) , by = count ]