Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Asymmetrikon posted:

basically a left paren that stretches to the end of the expression

I don't think I've ever seen this analogy for $, but it's extremely intuitive. I'll have to use that when explaining to other people.

Adbot
ADBOT LOVES YOU

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Yeah that's pretty good

Shaman Tank Spec
Dec 26, 2003

*blep*



I'm back with more hot Haskell questions.

Right now I'm doing a program that runs a Hill Cipher on a string. I've got everything else working, except I want to expand it to read stuff from files and user inputs, so that it can be executed and then the program queries the user for commands and reads my encryption and decryption keys from files.

Here's how it works:
- Build a 3x3 matrix from numbers (I originally used the Data.Matrix constructor fromLists and specified 3x3 Integer lists as the keys)
- Right now I want to read my Integers from files.
- I've got the process about 95% of the way down, I'd say. I can handle the user input, I can read files, I can parse the contents of the files from IO String to IO Int using read. But when I try to construct the matrices, it all falls down with the error message:

code:
Couldn't match expected type `IO (Matrix Integer)' with actual type `Matrix a0'
I'm pretty sure this is either a syntax thing or a small problem somewhere else. Here are the relevant parts of my code:

code:
--Attempting to construct the matrix (this is in a do block), encryptFile is received from arguments.
matrixKey <- fromList 3 3 (fromFileToList encryptFile)

[...]

fromFileToList x = do
  handle <- openFile x ReadMode
  contents <- hGetContents handle
  let words = lines contents
  return (map read words :: [Int])
Now, from what I understand, as long as I'm in a do block and I'm using IO actions in a <- way and making sure I'm passing IO [Int]s and not IO [String]s or something, this should work. It works in places where Strings are needed and IO [String]s are used, so I can't understand why it falls apart here.

Also, a general question about visibility in Haskell. I was told that Haskell is very lenient with visibility, but it doesn't seem to be so. If I try to run constuctors in my main do block, I get a "not in scope" error if I try to access them elsewhere.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
fromFileToList has type:
code:
fromFileToList :: FilePath -> IO [Int]
while fromList has type:
code:
fromList :: Int -> Int -> [a] -> Matrix a
You're trying to pass in an IO [Int] where fromList expects an [Int]. You can replace the matrixKey thing with the following:
code:
fileList <- fromFileList encryptFile
let matrixKey = fromList 3 3 fileList
and it should work.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
Also, I'm not quite sure what you mean with the constructor question. Can you give an example?

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
A slightly more advanced way to do the same thing, if you want to learn a bit more, would be to partially apply fromList and then pass it to liftM from Control.Monad, and then compose it with fromFileToListlike this:

code:
matrixKey <- (liftM (fromList 3 3) . fromFileToList) encryptFile

Shaman Tank Spec
Dec 26, 2003

*blep*



Asymmetrikon posted:

Also, I'm not quite sure what you mean with the constructor question. Can you give an example?

First of all, thanks. This is really helpful!

Second of all, sure!

Let's say I want to construct two matrices, encryptKey and decryptKey. I wanted to do that in my main block, which I figured should do housekeeping things first and then launch another do function, doLoop. That handles the user's inputs, parses them and then calls various other functions to encrypt and decrypt inputs.

If I try to run my matrix constructors in the main function's do block, I get a "not in scope" error when I try to access those matrices in the doLoop block (or even if I isolate the calls out of the doLoop block into an encryptWord x function which references, say, encryptKey as one of its arguments).

Here is some more relevant code:
code:
main = do
	(encryptFile:decryptFile:_) <- getArgs
	e_file <- fromFileToList encryptFile
	d_file <- fromFileToList decryptFile
	let matrixKey = fromList 3 3 e_file
	let decryptKey = fromList 3 3 d_file
	doLoop
code:
doLoop = do
[...]
	command <- fmap (splitOn " ") getLine
	
	if (head command) == "encrypt" then do
		putStrLn $ "Encrypting " ++ (last command)
		putStrLn $ encryptWord (last command)
		putStrLn $ ""
		doLoo
Theeen the actual encryptWord function:

code:
encryptWord :: String -> String
encryptWord x = convertFromNumbers $ toList (multStd (fromLists $ splitToVectors (padToThree x)) matrixKey) 
That's a whole mess of functions that basically convert the input string to a list of numbers, builds a matrix out of them, multiplies that with the encryption key and then reverses the process to produce an encrypted string. The relevant part here is the reference to matrixKey. This produces a "Not in scope: 'matrixKey'" error on that line. Additionally, decryptKey is not in scope either.

If this was a normal programming language, I'd naturally introduce the variables matrixKey and reverseKey as class variables even if they were initialized and constructed in a function or method somewhere else, but as far as I understand that's not really an option with Haskell. I can't just give a type signature for them outside the do block or something, right? Or am I thinking too object oriented?

E: It works fine if instead of using discrete functions I then call from my doLoop block I just put the convertFromNumbers $ directly into them and build the matrices at the start of the doLoop. It just seems so wasteful!

Shaman Tank Spec fucked around with this message at 20:04 on Feb 14, 2016

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
I think I understand the confusion. Scope is explicit in Haskell - to ensure referential transparency, a function can only use the things that are passed in as arguments, or the things that are defined at the point that the function is defined (other top level functions, for instance.) matrixKey isn't defined when doLoop or encryptWord are defined, so you'll need to pass it in as an argument, like:

code:
doLoop matrixKey = do
[...]
	command <- fmap (splitOn " ") getLine
	
	if (head command) == "encrypt" then do
		putStrLn $ "Encrypting " ++ (last command)
		putStrLn $ encryptWord matrixKey (last command)
		putStrLn $ ""
		doLoop matrixKey
code:
encryptWord :: Matrix -> String -> String
encryptWord matrixKey x = convertFromNumbers $ toList (multStd (fromLists $ splitToVectors (padToThree x)) matrixKey)
and then you'd use (doLoop matrixKey) instead of doLoop.

Edit:

I think what people mean when they say that Haskell's visibility is lenient is that you can define a top-level function foo before another one bar, yet you can use bar in foo (technically before it's defined.) Haskell considers all top-level functions to be defined "at the same time."

Asymmetrikon fucked around with this message at 20:07 on Feb 14, 2016

Shaman Tank Spec
Dec 26, 2003

*blep*



Asymmetrikon posted:

I think what people mean when they say that Haskell's visibility is lenient is that you can define a top-level function foo before another one bar, yet you can use bar in foo (technically before it's defined.) Haskell considers all top-level functions to be defined "at the same time."

Yep, that was precisely it! Well, as usual you were a real help. Thanks so much!

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!

Der Shovel posted:

Yep, that was precisely it! Well, as usual you were a real help. Thanks so much!

No problem! I'm always happy to help people get into functional languages like Haskell. They can be really unintuitive coming from an imperative point-of-view, but I think that, once you get used to them, the rules you use to structure programs become very simple and easy to understand.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Are there any kind of projects you can do at home with Spark that would do any justice to the capabilities of the framework? Especially something visualization or graphics oriented? I know a team at work uses aggregating a NY taxi data set to visualize it but even that's only like 10GB, not exactly big data. I just want some stuff I can try that doesn't require a huge infrastructure to do, just to mess around with Spark.

piratepilates fucked around with this message at 03:47 on Feb 17, 2016

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

piratepilates posted:

Are there any kind of projects you can do at home with Spark that would do any justice to the capabilities of the framework? Especially something visualization or graphics oriented? I know a team at work uses aggregating a NY taxi data set to visualize it but even that's only like 10GB, not exactly big data. I just want some stuff I can try that doesn't require a huge infrastructure to do, just to mess around with Spark.

You're not going to have problems that can run on your laptop that are so "big data" they need a cluster. It's a contradiction.

The beauty of spark especially when written in Scala (or Java) is that if it works on your machine, it will work on a cluster. Use it to solve problems that can scale even if on a manageable data set that you could handle with awk or a simple python script to learn the platform.

Also, if you're portfolio building, the NYC taxi data set is horribly over used. We see thirty resumes with the same project from that data set every time a boot camp lets out.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



KernelSlanders posted:


Also, if you're portfolio building, the NYC taxi data set is horribly over used. We see thirty resumes with the same project from that data set every time a boot camp lets out.

Well now I'm curious what all of them are doing with it the exact same way.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





spark runs fine with no cluster behind it. we have a bunch of spark jobs running on aws lambda and you only get like 1.5 gigs of memory there

no_funeral
Jul 4, 2004

why
OK. What the gently caress. value_orientation is an enum.

code:
2.2.1 :031 > Value.find(18)
 => #<Value id: 18, created_at: "2016-01-27 18:12:25", updated_at: "2016-01-27 18:12:25", name: "Chaos", value_orientation: 0> 
2.2.1 :032 > Value.find(18).value_orientation
 => "survival" 
2.2.1 :033 > Value.where(value_orientation: 'making_a_difference')[3]
 => #<Value id: 18, created_at: "2016-01-27 18:12:25", updated_at: "2016-01-27 18:12:25", name: "Chaos", value_orientation: 0> 
2.2.1 :034 > Value.where(value_orientation: 'making_a_difference')[3].value_orientation
 => "survival" 
Am I losing my mind? This is rails 4/postgresql

edit: apparently i don't know how enums work when querying via string
code:
2.2.1 :061 > Value.where(value_orientation: Value.value_orientations['this_is_not_in_our_database']).count
 => 0 
2.2.1 :062 > Value.where(value_orientation: 'this_is_not_in_our_database').count
 => 20 

no_funeral fucked around with this message at 21:52 on Feb 17, 2016

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

piratepilates posted:

Well now I'm curious what all of them are doing with it the exact same way.

Heat map of pick ups and drop offs by time of day. Map showing most trafficked streets. Some combination of the two. Then there's the ML ones rather than the visualization ones. They'll do something like finding the Bayesian optimal location to pick up a fare, which is really just fitting a gaussian to the pick up location cloud, i.e., the same as the map of pickups by time of day. Mostly it's different ways of taking 2D slices through a 3D data set.

These projects show that you can manipulate data, apply descriptive statistics, and use a plotting package. They don't show that you can structure a problem analytically or write software to solve said problem.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.
Yeah, double post.

Sensing the obvious question: what would I rather see, I'd rather see you use a more unique data set and actually test business relevant hypothesis with it. In addition to the analysis this shows me you can 1) identify a business relevant hypothesis, 2) test a hypothesis, and 3) find a dataset on your own.

Failing that, if you must use the taxi data, do something interesting that requires expanding beyond what you're handed. Write a web scraper to find the times and locations that broadway shows start and let out. What's the impulse response on the likelihood of a pickup/drop off around the theater? Bonus points to expand beyond Broadway shows: Opera at the Met, concerts vs. hockey games vs. basketball games at MSG, events at Bowery Ballroom or Terminal 5, etc. Where do Rangers fans live? Where to Knicks fans live? Are they different?

There's only a few flights a day each to JFK and LGA from Kingston and Santo Domingo. Do you see an uptick in rides from those airports to Flatbush and Washington Heights respectively around those times? Do you see the same effect in reverse on the outbound flights? If not, why might there be a difference?

This may seem like it assumes a lot of knowledge of New York, and that's the point. If you're going to dive into a data set, you need to understand it. I don't care that you can tell me that sales of our blue widgets are down 10% this month. Your project should prove to me that you can tell me why..

Gothmog1065
May 14, 2009
Okay goons, help point me in the right direction.

Basic info:

OS: WIn 10 Pro
Current programming knowledge: Low level python (3), some VBS, no access to powershell (that I know of yet).

My manager has tasked me with something and I'd like to get some pointers on the best way to accomplish this. I have a list of computer names that is currently in a spreadsheet. I can export this to a .csv if it would help. What I want to do is take this list (It's 85 computers long), iterate over the list, and create a new text document when run that lists the computer name, the owner (Going to have to get specifics if this is the last user logged in or if it's according to this spreadsheet I have, or if I need to pull it from AD), possibly the IP via nslookup or however.

I know this should be fairly simple, but here's the question: What is the best/easiest way to go about this? I can set up a python script, and put it in a self-contained .exe (Not sure if py2exe is supported with 3.5). Or can it done via a simpler method such as creating a .vbs or something else?

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Gothmog1065 posted:

Okay goons, help point me in the right direction.

Basic info:

OS: WIn 10 Pro
Current programming knowledge: Low level python (3), some VBS, no access to powershell (that I know of yet).

My manager has tasked me with something and I'd like to get some pointers on the best way to accomplish this. I have a list of computer names that is currently in a spreadsheet. I can export this to a .csv if it would help. What I want to do is take this list (It's 85 computers long), iterate over the list, and create a new text document when run that lists the computer name, the owner (Going to have to get specifics if this is the last user logged in or if it's according to this spreadsheet I have, or if I need to pull it from AD), possibly the IP via nslookup or however.

I know this should be fairly simple, but here's the question: What is the best/easiest way to go about this? I can set up a python script, and put it in a self-contained .exe (Not sure if py2exe is supported with 3.5). Or can it done via a simpler method such as creating a .vbs or something else?

I'd stick with Python for now. Don't waste any more of your life learning VBS, it is a terrible language.

Amberskin
Dec 22, 2013

We come in peace! Legit!

Gothmog1065 posted:


I know this should be fairly simple, but here's the question: What is the best/easiest way to go about this? I can set up a python script, and put it in a self-contained .exe (Not sure if py2exe is supported with 3.5). Or can it done via a simpler method such as creating a .vbs or something else?

If you have to create a document, perhaps an ipython notebook could be a good choice.

kloa
Feb 14, 2007


I can't get to the C# thread (Awful app is crashing on forum list :ironicat:) but need some advice on workflow for an ASP.NET app.

Our backend stores dropdown values as bytes, and I use DropDownListFor and convert the numbers to text values (3 becomes "Consistent") on the View. However, I want to replace the DropDownListFor and just use a DisplayFor or some equivalent instead on a read-only View, and I'm not really sure where to convert the number to text. I can't do it in the ViewModel since it can't convert byte to string, so I'm looking for another way to change it only within the View (one-way change).

I found a few SO solutions, but it's a bunch of case statements within the View which I want to avoid if possible.


e: Learned about DisplayTemplates - nothing to see here!

kloa fucked around with this message at 02:30 on Feb 19, 2016

raminasi
Jan 25, 2005

a last drink with no ice

kloa posted:

I can't get to the C# thread (Awful app is crashing on forum list :ironicat:) but need some advice on workflow for an ASP.NET app.

Our backend stores dropdown values as bytes, and I use DropDownListFor and convert the numbers to text values (3 becomes "Consistent") on the View. However, I want to replace the DropDownListFor and just use a DisplayFor or some equivalent instead on a read-only View, and I'm not really sure where to convert the number to text. I can't do it in the ViewModel since it can't convert byte to string, so I'm looking for another way to change it only within the View (one-way change).

I found a few SO solutions, but it's a bunch of case statements within the View which I want to avoid if possible.

I've never used ASP.NET for anything ever, but will a Converter not do what you want here?

mystes
May 31, 2006

Gothmog1065 posted:

Okay goons, help point me in the right direction.

Basic info:

OS: WIn 10 Pro
Current programming knowledge: Low level python (3), some VBS, no access to powershell (that I know of yet).

My manager has tasked me with something and I'd like to get some pointers on the best way to accomplish this. I have a list of computer names that is currently in a spreadsheet. I can export this to a .csv if it would help. What I want to do is take this list (It's 85 computers long), iterate over the list, and create a new text document when run that lists the computer name, the owner (Going to have to get specifics if this is the last user logged in or if it's according to this spreadsheet I have, or if I need to pull it from AD), possibly the IP via nslookup or however.

I know this should be fairly simple, but here's the question: What is the best/easiest way to go about this? I can set up a python script, and put it in a self-contained .exe (Not sure if py2exe is supported with 3.5). Or can it done via a simpler method such as creating a .vbs or something else?
When you say you have "no access to powershell" that just means the default execution policy is set, right? Or you actually can't even get an interactive powershell session? Because if the former, this is the sort of task powershell is good for and, hey, until you have the permissions worked out there's always "powershell -executionpolicy bypass script.ps1" (if you're on a domain you should probably sign the scripts when you actually distribute them, and have the execution policy set to allow signed scripts only, though).

Otherwise, you can no doubt do this in python, as well. Definitely try to avoid learning vbscript in 2016.

mystes fucked around with this message at 01:49 on Feb 19, 2016

Gothmog1065
May 14, 2009

mystes posted:

Otherwise, you can no doubt do this in python, as well. Definitely try to avoid learning vbscript in 2016.

Thanks everyone. I'm doing this in Python for now. I might start looking into Powershell, but I need to get the month of lunches book and dive into it. Not sure what my boss is doing (other than testing my learning ability), but it's completely out of scope of my job, which is interesting.

Quandary
Jan 29, 2008
I apologize if there's a thread for this, but I'm developing curriculum for a intro programming class for kids, and we're thinking about teaching it in MIT's Scratch. Does anyone have any experience teaching kids in Scratch or know of any resources about teaching kids, particularly any good lesson plans?

Cast_No_Shadow
Jun 8, 2010

The Republic of Luna Equestria is a huge, socially progressive nation, notable for its punitive income tax rates. Its compassionate, cynical population of 714m are ruled with an iron fist by the dictatorship government, which ensures that no-one outside the party gets too rich.

Can't personally speak to scratch but my fiance is a primary teacher and used it with her class a while ago. She was very happy with it.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Gothmog1065 posted:

Thanks everyone. I'm doing this in Python for now. I might start looking into Powershell, but I need to get the month of lunches book and dive into it. Not sure what my boss is doing (other than testing my learning ability), but it's completely out of scope of my job, which is interesting.

https://www.devopsonwindows.com/3-ways-remotely-view-who-is-logged-on/

mystes
May 31, 2006

You probably want to use wmi directly to do this programmatically though, rather than parsing the output of one of these commands. I think you can do this in either powershell without anything extra, or in python if you install the wmi module.

Gothmog1065
May 14, 2009

mystes posted:

You probably want to use wmi directly to do this programmatically though, rather than parsing the output of one of these commands. I think you can do this in either powershell without anything extra, or in python if you install the wmi module.

Time to learn powershell it seems!

Shaman Tank Spec
Dec 26, 2003

*blep*



Asymmetrikon posted:

They can be really unintuitive coming from an imperative point-of-view, but I think that, once you get used to them, the rules you use to structure programs become very simple and easy to understand.

Yeah, I don't know what the hell my problem is, but I'm just having such a hard time grasping the big picture. I know how to do some things, but ... well, here's an example.

I've been toying with binary search trees. I made one a while ago following the example from Learn You A Haskell which I've been following. I then created a bunch of auxiliary functions for returning values between X and Y from the tree etc.

But making those lists by hand has been very painful. I've wanted to make a function where I can give it a list and it will step through that list one by one, running my treeInsert function on each one and spitting out a finished tree in the end.

I spent HOURS trying to figure it out somehow, until I stumbled onto a post on the topic and it turned out that the solution was one single line of code using foldl (or foldr). Like I knew folds but for whatever reason I just couldn't figure it out.

Haskell constantly makes me feel like a loving moron even though I'm pretty good with "traditional" OOP languages.

E: but man I gotta say, when I do get it right and after hours of frustration finally figure out the implementation and can, for instance, make my binary search tree a Monoid, it feels loving GREAT.

E2: Honestly, my big problem is that possibly because Haskell is a relatively rare language and not in mainstream use, it doesn't have the kind of widespread community support that something like C#, Python or Java enjoys. With those languages if I'm not entirely sure about something I can google it and turn up a LOT of information which will inevitably nudge me along in the right direction.

With Haskell googling something usually turns up relatively few hits and those hits often are extremely unhelpful being either very terse API dumps or some guy who is more interested in being clever than helpful.

Shaman Tank Spec fucked around with this message at 16:18 on Feb 19, 2016

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Der Shovel posted:

Yeah, I don't know what the hell my problem is, but I'm just having such a hard time grasping the big picture. I know how to do some things, but ... well, here's an example.

I've been toying with binary search trees. I made one a while ago following the example from Learn You A Haskell which I've been following. I then created a bunch of auxiliary functions for returning values between X and Y from the tree etc.

But making those lists by hand has been very painful. I've wanted to make a function where I can give it a list and it will step through that list one by one, running my treeInsert function on each one and spitting out a finished tree in the end.

I spent HOURS trying to figure it out somehow, until I stumbled onto a post on the topic and it turned out that the solution was one single line of code using foldl (or foldr). Like I knew folds but for whatever reason I just couldn't figure it out.

Haskell constantly makes me feel like a loving moron even though I'm pretty good with "traditional" OOP languages.

E: but man I gotta say, when I do get it right and after hours of frustration finally figure out the implementation and can, for instance, make my binary search tree a Monoid, it feels loving GREAT.

E2: Honestly, my big problem is that possibly because Haskell is a relatively rare language and not in mainstream use, it doesn't have the kind of widespread community support that something like C#, Python or Java enjoys. With those languages if I'm not entirely sure about something I can google it and turn up a LOT of information which will inevitably nudge me along in the right direction.

With Haskell googling something usually turns up relatively few hits and those hits often are extremely unhelpful being either very terse API dumps or some guy who is more interested in being clever than helpful.

This is a typical experience, but keep at it and eventually things will start clicking. The functional paradigm is different enough that it's almost like learning programming all over again. I had the same experience where I found it easy to switch between languages and then I tried Haskell and was completely humbled. Moving around between imperative languages the main differences are the typing discipline and some syntax. Moving between imperative and functional languages requires changing the whole way you approach problems. And Haskell is particularly unforgiving in that it won't let you try and doing something in an imperative way.

Vitamean
May 31, 2012

I don't know what I'm doing! (VBScript)

I'm a workstudy in the IT department of my school. Sometimes my boss will hand something off to me and most of the time I can figure it out.

I'm not even 100% sure how this new thing works, though. I was handed an asp file that's suppose to pull from the school's LDAP server and populate a directory on their Cisco phone system. Thing is right now the code pulls everyone, including staff, faculty, and students, and they want it to not pull students.

I think I need to change two things. First to change this so that it picks up their classification:

code:
sQuery	= "(&(|(objectclass=user)(objectclass=contact))(givenName=" & sFirstName & "*)(sn=" & sLastName & "*)(ipPhone=*));"

'====================== don't edit below here... 

sQuery = sQuery & sProperties & ";subtree"

oCmd.CommandText = "<" & sDomainADsPath & ">;" & sQuery
and then change something in each of these loops so that it'll bypass anyone who has a student classification:

code:
if oRecordSet.RecordCount <= 32 then
	while not oRecordSet.EOF
		response.write ("<DirectoryEntry>")
		response.write ("<Name>" & oRecordSet.Fields("givenName") & " " & oRecordSet.Fields("sn")  & "</Name>")
		response.write ("<Telephone>" & oRecordSet.Fields("ipPhone") & "</Telephone>")
		response.write ("</DirectoryEntry>")
		oRecordSet.MoveNext 
	wend
	response.write ("<SoftKeyItem><Name>Dial</Name><URL>SoftKey:Dial</URL><Position>1</Position></SoftKeyItem>")
	response.write ("<SoftKeyItem><Name>Exit</Name><URL>SoftKey:Exit</URL><Position>4</Position></SoftKeyItem>")
else 
	if sPage = "" then sPage = 1
	oRecordSet.absoluteposition = 32 * sPage - 31
	for intRecord = 1 to 32
		response.write ("<DirectoryEntry>")
		response.write ("<Name>" & oRecordSet.Fields("givenName") & " " & oRecordSet.Fields("sn")  & "</Name>")
		response.write ("<Telephone>" & oRecordSet.Fields("ipPhone") & "</Telephone>")
		response.write ("</DirectoryEntry>")
		oRecordSet.MoveNext 
		if oRecordSet.EOF then exit for
	next 

	response.write ("<SoftKeyItem><Name>Dial</Name><URL>SoftKey:Dial</URL><Position>1</Position></SoftKeyItem>")
	
	if oRecordSet.RecordCount > sPage * 32 then 
		response.addheader "Refresh", ";url=" & "http://" & request.servervariables("SERVER_NAME") & ":" & request.servervariables("SERVER_PORT")
		 & request.servervariables("url") & "?page=" & sPage + 1 & "&f=" & sFirstName & "&l=" & sLastName & "&searchparam=" & 
		server.urlencode(sSearchparam)
		response.write ("<SoftKeyItem><Name>Next</Name><URL>SoftKey:Next</URL><Position>3</Position></SoftKeyItem>")		
	end if
	if 32 * sPage - 31 > 1 then 
		response.write ("<SoftKeyItem><Name>Prev</Name><URL>[url]http://[/url]"  & request.servervariables("SERVER_NAME") & ":" & 
		request.servervariables("SERVER_PORT") & request.servervariables("url") & "?page=") 
		response.write (sPage-1)
		response.write ("&amp;f=" & sFirstName & "&amp;l=" & sLastName & "&amp;searchparam=" & Server.urlEncode(sSearchparam))
		response.write ("</URL><Position>2</Position></SoftKeyItem>")
	end if
	response.write ("<SoftKeyItem><Name>Exit</Name><URL>SoftKey:Exit</URL><Position>4</Position></SoftKeyItem>")
end if
And I can probably do this through some trial and error while dredging up some of my VBScript knowledge I haven't touched in half a decade.

But I feel like I should be able to specify in the first line to only select users who are not students, which would be ten times easier but I have no idea how to do it because I have pretty basic SQL knowledge and that isn't meshing with how that query is presented to me. I've tried googling around but I'm not sure what exactly this is called, and googling for sQuery turns up pages like this that look completely different.

I guess what I'm asking is if the second method is even possible, and if it is what exactly is that kind of query called and where can I find some documentation on it.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Moldy Taxes posted:

I don't know what I'm doing! (VBScript)

I'm a workstudy in the IT department of my school. Sometimes my boss will hand something off to me and most of the time I can figure it out.

I'm not even 100% sure how this new thing works, though. I was handed an asp file that's suppose to pull from the school's LDAP server and populate a directory on their Cisco phone system. Thing is right now the code pulls everyone, including staff, faculty, and students, and they want it to not pull students.

I think I need to change two things. First to change this so that it picks up their classification:

code:
sQuery	= "(&(|(objectclass=user)(objectclass=contact))(givenName=" & sFirstName & "*)(sn=" & sLastName & "*)(ipPhone=*));"

'====================== don't edit below here... 

sQuery = sQuery & sProperties & ";subtree"

oCmd.CommandText = "<" & sDomainADsPath & ">;" & sQuery
and then change something in each of these loops so that it'll bypass anyone who has a student classification:

code:
if oRecordSet.RecordCount <= 32 then
	while not oRecordSet.EOF
		response.write ("<DirectoryEntry>")
		response.write ("<Name>" & oRecordSet.Fields("givenName") & " " & oRecordSet.Fields("sn")  & "</Name>")
		response.write ("<Telephone>" & oRecordSet.Fields("ipPhone") & "</Telephone>")
		response.write ("</DirectoryEntry>")
		oRecordSet.MoveNext 
	wend
	response.write ("<SoftKeyItem><Name>Dial</Name><URL>SoftKey:Dial</URL><Position>1</Position></SoftKeyItem>")
	response.write ("<SoftKeyItem><Name>Exit</Name><URL>SoftKey:Exit</URL><Position>4</Position></SoftKeyItem>")
else 
	if sPage = "" then sPage = 1
	oRecordSet.absoluteposition = 32 * sPage - 31
	for intRecord = 1 to 32
		response.write ("<DirectoryEntry>")
		response.write ("<Name>" & oRecordSet.Fields("givenName") & " " & oRecordSet.Fields("sn")  & "</Name>")
		response.write ("<Telephone>" & oRecordSet.Fields("ipPhone") & "</Telephone>")
		response.write ("</DirectoryEntry>")
		oRecordSet.MoveNext 
		if oRecordSet.EOF then exit for
	next 

	response.write ("<SoftKeyItem><Name>Dial</Name><URL>SoftKey:Dial</URL><Position>1</Position></SoftKeyItem>")
	
	if oRecordSet.RecordCount > sPage * 32 then 
		response.addheader "Refresh", ";url=" & "http://" & request.servervariables("SERVER_NAME") & ":" & request.servervariables("SERVER_PORT")
		 & request.servervariables("url") & "?page=" & sPage + 1 & "&f=" & sFirstName & "&l=" & sLastName & "&searchparam=" & 
		server.urlencode(sSearchparam)
		response.write ("<SoftKeyItem><Name>Next</Name><URL>SoftKey:Next</URL><Position>3</Position></SoftKeyItem>")		
	end if
	if 32 * sPage - 31 > 1 then 
		response.write ("<SoftKeyItem><Name>Prev</Name><URL>[url]http://[/url]"  & request.servervariables("SERVER_NAME") & ":" & 
		request.servervariables("SERVER_PORT") & request.servervariables("url") & "?page=") 
		response.write (sPage-1)
		response.write ("&amp;f=" & sFirstName & "&amp;l=" & sLastName & "&amp;searchparam=" & Server.urlEncode(sSearchparam))
		response.write ("</URL><Position>2</Position></SoftKeyItem>")
	end if
	response.write ("<SoftKeyItem><Name>Exit</Name><URL>SoftKey:Exit</URL><Position>4</Position></SoftKeyItem>")
end if
And I can probably do this through some trial and error while dredging up some of my VBScript knowledge I haven't touched in half a decade.

But I feel like I should be able to specify in the first line to only select users who are not students, which would be ten times easier but I have no idea how to do it because I have pretty basic SQL knowledge and that isn't meshing with how that query is presented to me. I've tried googling around but I'm not sure what exactly this is called, and googling for sQuery turns up pages like this that look completely different.

I guess what I'm asking is if the second method is even possible, and if it is what exactly is that kind of query called and where can I find some documentation on it.

The "oCmd.CommandText = "<" & sDomainADsPath & ">;" & sQuery" line is setting the SQL of a command object. sQuery is just a poor name for part of the string that gets built out of. That being said, I don't know WTF is going on in most of that string. You should be able to add a WHERE clause in there somehow, but that will take some trial and error.

See if you can print that full oCmd.CommandText out to the screen to see what it ends up looking like, might help figure out what is going on.

it is
Aug 19, 2011

by Smythe
What is the absolute easiest way to turn a javascript string into a file on my desktop in Windows? If you're in a room full of 100 people with identical stock Windows machines with a.html on the desktop and a.html includes a random javascript string, and the first person to pipe that string into a file on their desktop gets $1,000,000, what are you going to do?

It's not actually a webapp at all, it's just a data collection tool that happens to be written in HTML and javascript. I'm "hosting" it on my own desktop and opening it by clicking on the HTML file and it is absolutely the most beautiful and wonderful thing in the world except for the fact that I don't know how to put "var inputs" into a file where the entire rest of the project can begin.

OR! To solve the problem I actually care about, I want to record and save my controller movements for machine learning stuff, in a format I already understand. I'm stuck on the saving part. This is language- and technology-agnostic; it's just the thing that would enable me to get to the fun part, which is the analysis.

I found a tutorial: http://gamedevelopment.tutsplus.com/tutorials/using-the-html5-gamepad-api-to-add-controller-support-to-browser-games--cms-21345

I copied and pasted the third HTML file and saved it on my desktop. I get to it by opening it in chrome. I slightly modified the javascript in it to append to a string every time the controller updates. When some condition happens, I want to basically do "file.write(str)" and clear the string and then I am DONE.

What do I do?

EDIT:

Found a solution; will implement when I get home

code:
function download(text, name, type) {
    var a = document.createElement("a");
    var file = new Blob([text], {type: type});
    a.href = URL.createObjectURL(file);
    a.download = name;
    a.click();
}

it is fucked around with this message at 20:58 on Feb 24, 2016

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
You could use a Blob, like in this fiddle.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Asymmetrikon posted:

You could use a Blob, like in this fiddle.

Doesn't work in FF, I think it requires you to attach to an anchor like so:

https://jsfiddle.net/o4cpcL15/

Also IE is dumb, as usual, and the download attribute doesn't work.

Jewel
May 2, 2009

I had to do something like this in IE once and there's actually no method for saving blobs. The closest accepted method is a flash file someone made that's invisibly embedded and routes the input in and opens a save dialog (perhaps there's a way to just Save the file too but not sure).

it is
Aug 19, 2011

by Smythe
Wow browser compatibility is weird. I'm always really impressed when front-end people can keep track of all that.

Thanks for help y'all :D

JawnV6
Jul 4, 2004

So hot ...
There's no way to just email it to yourself? Spin up a server that provides a single endpoint to POST strings and store them to disk? Throw an error somewhere that's logged with the string smuggled in?

Adbot
ADBOT LOVES YOU

it is
Aug 19, 2011

by Smythe

JawnV6 posted:

There's no way to just email it to yourself? Spin up a server that provides a single endpoint to POST strings and store them to disk? Throw an error somewhere that's logged with the string smuggled in?
That sounds like way more work than copying and pasting a little bit of javascript into a notepad document, never to be touched again. Here's every single line of code for this project so far (there's a little bit of pseudocode because my computer is at home):

code:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
 
    </head>
    <body>
 
    <div id="gamepadPrompt"></div>
    <div id="gamepadDisplay"></div>
 
    <script>
    var hasGP = false;
    var repGP;
    var output = ""; //the entire sum total of the output of the app so far
 
    function canGame() {
        return "getGamepads" in navigator;
    }
 
    function reportOnGamepad() {
        var gp = navigator.getGamepads()[3];
        output = output + gp.axes[0] + "," + output + gp.axes[1] + new Date().millis + "\n";
    }
 
    $(document).ready(function() {
 
        if(canGame()) {
 
            var prompt = "To begin using your gamepad, connect it and press any button!";
            $("#gamepadPrompt").text(prompt);
 
            $(window).on("gamepadconnected", function() {
                hasGP = true;
                $("#gamepadPrompt").html("Gamepad connected!");
                console.log("connection event");
                repGP = window.setInterval(reportOnGamepad,100);
            });
 
            $(window).on("gamepaddisconnected", function() {
                console.log("disconnection event");
                $("#gamepadPrompt").text(prompt);
                window.clearInterval(repGP);
            });
 
            //setup an interval for Chrome
            var checkGP = window.setInterval(function() {
                console.log('checkGP');
                if(navigator.getGamepads()[0]) {
                    if(!hasGP) $(window).trigger("gamepadconnected");
                    window.clearInterval(checkGP);
                }
            }, 500);
        }
 
    });
    </script>
    </body>
</html>
Once the variable "output" is in my hard drive I am done.

it is fucked around with this message at 21:43 on Feb 24, 2016

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply