• Live Streamers

    Gaming
    4
    0 Votes
    4 Posts
    1k Views
    SkyhijinxS
    http://www.twitch.tv/skyhijinx I’ve streamed Minecraft a few times but it’s been quite a while ago. My favorite game to chill with right now is Hearthstone and I play it (mostly) on my Nvidia Shield Tablet. I plan to start streaming from it soon.
  • Rhyme Thread

    The lounge
    3
    0 Votes
    3 Posts
    553 Views
    AlmostA
    Slant rhymes are bullshit, prick.
  • Game of Thrones Season 5 Trailer

    The lounge game of thrones season 5
    6
    0 Votes
    6 Posts
    890 Views
    SchamperS
    New trailer. I think this is the one that debuted at the Apple event yesterday. Although the Verge described it as Arya walking through an Apple store so I’m not too sure. https://www.youtube.com/watch?v=F9Bo89m2f6g
  • Windows 10

    Tech windows microsoft windows 10 windows 8 technical preview metro start menu
    6
    1 Votes
    6 Posts
    1k Views
    LeoL
    Dat crossplatform play tho
  • 0 Votes
    4 Posts
    703 Views
    ScuzzS
    Cry of Fear was a bit of a failure last night but we managed to rescue the game night with @GoaNy’s suggest of an online board game. Boardgame online It worked out to be quite an interesting and fun game to play. Definitely worth another go with some more people, I can imagine it being even more crazy than it was last night.
  • Blog Theme

    Announcements blog theme
    3
    1 Votes
    3 Posts
    835 Views
    SchamperS
    @Scuzz look at you all doing things and stuff.
  • Minecraft Parkour Gaming Night [weekend of 2015-2-6]

    Gaming minecraft parkour
    10
    2 Votes
    10 Posts
    1k Views
    LeoL
    This was nice.
  • [nodebb-plugin-imdb] IMDB Information

    Development and Coding nodebb imdb plugin
    14
    3 Votes
    14 Posts
    2k Views
    AlmostA
    Look at you getting things to work! Nice job.
  • Star Wars Trailer

    The lounge
    7
    1 Votes
    7 Posts
    1k Views
    JellyformeJ
    Can’t wait for this and Jurassic World to come out
  • Must watch films

    The lounge
    25
    2 Votes
    25 Posts
    4k Views
    JellyformeJ
    Where the Red Fern Grows (book and movie) Dumbo 21 and 22 Jump Street
  • 2 Votes
    5 Posts
    893 Views
    JellyformeJ
    Thanks, I needed this post. The name icon was annoying.
  • Greetings

    Introductions
    4
    0 Votes
    4 Posts
    1k Views
    JellyformeJ
    Welcome to the site!
  • A Brief Introduction to Haskell

    Development and Coding haskell
    1
    4 Votes
    1 Posts
    401 Views
    AlmostA
    A brief introduction to Haskell So, what I really wanted to do was to make a post about how functional programming concepts are useful after a discussion that came up in the shoutbox over my suggested use of a function as the second argument of string.replace in @Scuzz’s omdb plugin thread, but I realized that some of the more subtle examples are hard to show without rigorous syntax. So, I thought I would use this post to outline a bit of Haskell syntax which will touch on some functional concepts and lay the ground work for understanding examples in a later post arguing the utility of functional programming. DISCLAIMER: I’m not an expert in Haskell, nor have I built any real software with it, so forgive me if I remain in the conceptual domain So, here we go! First, if you want to play around with Haskell, it seems the go to is the Glasgow Haskell Compiler (GHC). Check out the Installation page at haskell.org (P.S. on mac brew install ghci) Maths Arithmetic As with all of our favorite interpreted languages, we can sit at the interpreter and do math all day: > 2 + 4 6 > 2 * 4 8 > 2 ** 4 -- 2 ^ 4 (line comments in Haskell begin with --) 16.0 Great, so we know we have some predefined types and operations (technically speaking in the manner we’ve presented above, those literals are not primitives; they are actually boxed, but we’ll get there in time). To exit the interpreter, use :quit Variables Like other languages, we can bind an expression to a name. > let x = 10 > x 10 Variables MUST begin with a lowercase letter. Unlike other languages, we cannot modify the value of x in a literal sense. We can rebind x, but this will create a new object rather than updating the old one. This leads to an important result: > let x = 10 > x 10 > let x = x + 10 > x In our favorite imperative language, we would expect to see the value of x updated to 20. However in Haskell it doesn’t evaluate. Why? because we have defined x in terms of itself. If we try to expand it, we get x + 10. Expand that, we get x + 10 + 10. If that doesn’t make sense, think about it this way: what we said is “where ever you see x replace it with x + 10”. Now, if I asked you “what is x?” here, you can only answer “x + 10” As you can see, this can never resolve to a value. Functions Of course, we can write our own math functions > let addOne x = x + 1 > addOne 1 2 The syntax for defining a function is let <function name> <variables> = <expression> The syntax for calling is just <function name> variables. Function names MUST begin with a lowercase letter. The interesting thing in Haskell (as well as other functional languages) is that functions are first-class citizens, meaning they can be treated like any other data. This allows us to do things like pass functions as arguments. > let square x = x * x > let applyTwice f x = f (f x) > square 2 4 > applyTwice square 2 -- (2^2)^2 16 This is obviously a contrived example, but it shows that we can pass a function and then call that function. Loading Haskell files Ok, before we go any further, lets get off the cumbersome interpreter. A lot of future example code will be in files. When you see the ‘>’ you’ll know I’ve switched back to the interpreter, but just to make it clear, I’ll always show myself loading the file in question e.g. -- add.hs add x y = x + y -- Function declaration syntax in a file (no need for let) > :load add -- load syntax (leave off the .hs) [1 of 1] Compiling Main ( add.hs, interpreted ) Ok, modules loaded: Main. > add 2 4 6 Data Custom Data Types So at this point, we know how to do stuff with built in types declare variables declare and invoke functions load code from a file Next, we would like to be able declare our own data types, much like being able to define our own classes. For this section, we will be implementing our own Bool type which we’ll call Loob with values Yes and No -- loob.hs data Loob = Yes | No data types MUST begin with a capital letter, like how functions must be lowercase. What did this actually do, @Almost? This defines a new data type, Loob with 2 data constructors, Yes and No. There isn’t a good equivalent to a data constructor in imperative languages, but the easiest way to think about it is kind of like an enum. We will see later how this notion isn’t quite right. enum Loob { Yes, No } Let’s take a look at our new type. > :load loob > let x = Yes > x Yes > :type x -- Gets type information from a variable x :: Loob -- Format: <name> :: <type> The let x = Yes statement instructs the interpreter to use the Yes data constructor to instantiate a new Loob and assign it to the variable x. Meaning the data of x is now Yes and the type of x is now Loob. In imperative space this is kind of like Loob x = Loob.Yes Going back to loob.hs, let’s define our own and function which we’ll call dna. -- loob.hs data Loob = Yes | No dna Yes Yes = Yes dna No _ = No dna _ No = No > load loob.hs > dna Yes Yes Yes > dna Yes No No > dna No Yes No > dna No No No This example shows off a couple of important points in Haskell. Functions can take arbitrary parameters the _ in the function definition means “any argument” in can be any type, any value, we don’t care. We know that No and Anything is always No, so we don’t even need to look at the second argument. This does have the side effect that dna No 1234 is defined as No which may or may not be desirable. Since we don’t give _ a name, we can’t use it in the body of our function. It literally means “I don’t need to know, nor even care what this data is” Functions can have multiple definitions over the same argument data type It might be hard to see what I mean due to the usage of _ but we could have written out all the cases explicitly: dna Yes Yes = Yes dna No Yes = No dna Yes No = No dna No No = No In an imperative world, this should be alarming. We just overloaded dna 4 times and each one takes 2 Loob arguments! If I were to calls: > let x = No > let y = Yes > dna x y How should it know which of the 4 functions to use? This is where our enum notion falls apart. Haskell uses the data constructor for the variables to perform pattern matching to find the first definition that matches the input. therefore our example above explicitly matches the 2nd definition for dna, so that one will be used. While defining our own pseudo primitives is nice and all, can we define actually useful types, like say Pair? Sure. While we didn’t take advantage of it before, our data constructors can act as a tag for other data: -- pair.hs data Pair t = Pair t t -- Declare data type Pair of t (where t is an arbitrary type). You might write this as Pair<T> in C++ or Java left (Pair x y) = x right (Pair x y) = y Don’t be confused here. I’ve named both the data type and data constructor “Pair”. in our functions, left and right, the argument is weird. That looks like how we construct a Pair doesn’t it? That’s exactly what it is. Haskell’s pattern matching basically says “Could I use this syntax to construct the object that you gave me? If yes then we have a match, if not we don’t have a match” To try it out: > :load pair > let p = Pair 1 2 > left p 1 > right p 2 Lists Haskell’s list syntax is similar to that of python: > [1,2,3,4] [1,2,3,4] Haskell, however, has syntax to create a list over a range: > [1..10] [1,2,3,4,5,6,7,8,9,10] One interesting fact about Haskell lists, due to the fact that Haskell performs lazy evaluation, an infinite list is completely legal and will not cause a crash or hang unless you attempt to evaluate the whole list: > let x = [1..] > -- no crash :) Accessing an element of the list can be done with the !! operator. > let x = [1..] -- infinite list > x !! 9 10 -- 0 indexed Remember, the lazy evaluation means that only as much as is actually used is evaluated which means that indexing an infinite list is completely legal. Given a list, you can prepend it with the : operator > let x = [2,3,4] > 1:x [1,2,3,4] This is handy since we can use this list building syntax as a pattern in a function (as we discussed in the last section) > let head (x:xs) = x -- x is the first element, xs is the rest of the list > head [1,2,3] 1 > let tail(x:xs) = xs > tail [1,2,3] [2,3] What we’re saying here is that the argument of head and tail is “Something (x) appended to a list (xs)” An aside, Haskell represents strings as lists of characters > head "Almost" 'A' :type Simple types I brought up :type discreetly in the custom data types section. You can learn a lot about how Haskell works by examining the output of :type. > :type 1 1 :: Num a => a Read: 1 has type (Num a) which reduces to a What this actually tells us is that: 1 is not a primitive, but rather of type a a is restricted to those types in the Typeclass Num That second point is similar to the concept of requiring that a generic type extends some known type in Java: public class Foo<? extends Collection> Other simple examples: > :t True -- :t works in place of :type True :: Bool > :t "Almost" "Almost" :: [Char] > :load loob -- from a previous example > :t Yes Yes :: Loob Function types we see some new syntax when we look at functions > let square x = x * x > :t square square :: Num a => a -> a Let’s ignore the point that a must be in the Num Type class and focus on the a -> a You can read this as a goes to a Meaning, square takes a variable of type a and returns a type a. As a concrete example, square can take an integer and return an integer. What’s the type of a function that takes 2 variables? > let add x y = x + y > :t add add :: Num a => a -> a -> a Hmm. a -> a -> a huh? “a goes to a goes to a?” I don’t get it. well, let’s apply some grouping to help us out. Let’s read it as a -> (a -> a) For now, trust me that this is better than (a -> a) -> a. I’ll explain why this is the case later. In this view, we read “a goes to (a goes to a).” Still a little fuzzy? Well, remember that a -> a means that it’s a function that takes an a and returns an a. Therefore a -> (a -> a) should mean that it’s a function that takes an a and returns a function that takes an a and returns an a. But that doesn’t make sense. Add takes 2 numbers and returns one number. It doesn’t take 1 number and return a function. Or does it? > :t (add 1) (add 1) :: Num a => a -> a Why did that work? Add takes two arguments god damn it! That should have given us an error! In imperative languages we’re used to the fact that a function that has two arguments requires that you supply two arguments when you call it (or at least that you specify default in the case of optional values such as int myFunc(int myInt, bool myBool = false)). Haskell has no such requirement. When we evaluate add 1 2 anywhere we see x we replace it with 1 and anywhere we see y we replace it with 2. Therefore add 1 2 is equivalent to 1 + 2 But what forces us to replace both x and y? Why can’t we replace just x? Why shouldn’t we call add 1 and get back 1 + y? > Because you can’t evaluate 1 + y, @Almost… Exactly. We can’t evaluate it until we are supplied with a y. So instead of trying to evaluate it, we just give that expression back and say “give me a y and I’ll evaluate this.” Gee, that sounds like a function, doesn’t it? Rather than just looking at the type, let’s try giving that new function a name > let addOne = add 1 > addOne 2 3 Woah. So it really does give us back a function. This magic process of partially evaluating functions is called Currying (Named after one Haskell Curry. The guy was a bit of a narcissist: he named both a programming language and a mathematical concept after himself.) Currying has a very useful property in that it naturally supports code reuse and encapsulation A simple contrived example: > let pow x y = y ** x --Yes, this is a bit backwards from how we usually think of pow > let square = pow 2 > let cube = pow 3 As you can see, it gives us a really simple way to build software without reinventing the wheel or writing many many lines of code. On a philosophical level, this makes it easy for us to show that cube is just a specific case of the more general pow. We don’t get such an obvious connection if we write cube as cube x = x * x *x. Now. An astute reader might be thinking: isn’t it kind of weird that we have 2 ways to evaluation functions: fully and partially? Actually this is not the case. There is only one way to evaluate a function: By supplying one argument. add 1 2 is not passing 2 arguments to add, rather it is actually evaluating as (add 1) 2 - apply 1 to add and the apply 2 to the resulting function. What implication does this have on how Haskell treats functions? In Haskell a function has exactly one input and exactly one output. Either or both of the input and output can be functions, but there cannot be more than one input or output. Now, before we wrap up our section on function types and currying, let’s talk about why we chose a -> (a -> a) instead of (a -> a) -> a. How do we read the second one? “add takes a function and returns an a”. This should be valid then: > add add clearly that doesn’t make sense, therefore (with all the handwaving I have in me :P) this is not a valid way to read that type signature. In the case where the argument truly is a function, Haskell will indicate that to us >let applyToOne f = f 1 > :t applyToOne applyToOne :: Num a => (a -> t) -> t Don’t be scared by t. This just tells us that the return type of the function f as well as applyToOne isn’t necessarily the same type as the type o the input to f e.g. > let equalsOne x = x == 1 > :t equalsOne equalsOne:: (Eq a, Num a) => a -> bool Conclusion tl;dr There is no tl;dr. Go read it. Whew. Rushed is probably a better word than brief. I hope that was reasonably easy to follow, and if not, please ask questions. I want to both help you understand and improve my own technical communication. If some sections make absolutely no sense even with some of my clarification, don’t worry too much. This stuff is very different from the usual “state-machine” style of programming that most of us are familiar with. But just because it’s different, don’t count it out. A lot of the concepts introduced in functional programming are making their way back into mainstream programming languages (e.g. Lambda Expressions, Nullable Types, LINQ). If you’re interested in learning more about Haskell, Learn You a Haskell for Great Good is the standard Textbook. It’s free online legally, so no need to go searching for it. Hope you enjoyed that. Help me improve this! <3 Almost
  • nodebb-plugin-shoutbox

    Development and Coding
    14
    2 Votes
    14 Posts
    2k Views
    ScuzzS
    Any updates on this @schamper?
  • 3 Votes
    1 Posts
    410 Views
    ScuzzS
    Just showing another project I did while I was at Uni. I dont know if it works, it should work as i submitted it as complete. But knowing me, i probably didnt care if it did work or not. I’m pretty sure we had to emulate a printer queue. Each printer job was a child process. Unix based OS only. Producer Producer /* Some printf functions are comment out, these are for debuggin purposes. */ #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> void fChildProcess(); int main(int argc, char *argv[]) { if (argc != 3) //Error out if correct command isnt entered { printf("Usage: %s SizeOfQueue NumberOfJobs\n", argv[0]); exit(0); } int columns = 2; int rows; int row; int *matrix; int shmid; int i, k, j, iNoj, iSoq; iSoq = atoi (argv[1]); iNoj = atoi (argv[2]); if (iNoj > iSoq) //Error if number of jobs is > than the size of the queue { printf("Number of Jobs has to be less than the Size of queue\n"); exit(0); } FILE *fp; pid_t pid; key_t key; key = 1220; //Identifier for shared memory rows = iSoq; //Sets the rows in the shared memory to +1 so there is space for flags k = 1; /* Makes a file that has the size of the queue in it */ fp = fopen("size", "w"); fprintf(fp, "%d", rows); fclose(fp); shmid = shmget(key, sizeof(int)*rows*columns, IPC_CREAT | 0666); if(shmid < 0) { perror("shmget"); _Exit(1); } //printf("Segment created\n"); matrix = (int *)shmat(shmid, 0, 0); //Attatch matrix[0*2 + 0] = 0; // Read/write flag matrix[0*2 + 1] = 1; //printf("%d\t%d\n", matrix[0*2 + 0], matrix[0*2 + 1]); while(1) { //printf("WHILE LOOP\n"); if(matrix[0*2 + 0] == 0) { for(i = 0; i < iNoj; i++) { if(matrix[0*2 + 1] <= iSoq) { //printf("FOR LOOP\n"); pid = fork(); if(pid < 0) { printf("fork Error"); exit(1); } if(pid == 0) { fChildProcess(); } else { //printf("PARENT\n"); k = matrix[0*2 + 1]; matrix[k*2 + 0] = pid; //Adds PID to shared memory matrix[0*2 + 1]++; printf("PID %d added\n", matrix[k*2 + 0]); } } } //printf("SHARED MEM\n"); //for(i = 0; i < iSoq; i++) //{ //printf("%d\t%d\n", matrix[(i+1)*2 + 0], matrix[(i+1)*2 + 1]); //} matrix[0*2 + 0] = 1; } else { sleep(1); //Wait for consumer wait(1); //Wait for child process } } shmctl( shmid, IPC_RMID, 0 ); } void fChildProcess() { for(;;); //infinite loop, child process runs forever. } Consumer Consumer /* Some printf functions are commented out, they are used for debugging purpses*/ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/signal.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> int main (int argc, char *argv[]) { if (argc != 2) //Errors out if correct arguments are not entered { printf ("Usage: %s AmmountToDelete\n", argv[0]); exit(1); } int rows; int columns = 2; int *matrix; int shmid; int i, j, iAtd; iAtd = atoi(argv[1]); FILE *fp; key_t key; //Opens the size file to get the size of the queue fp = fopen("size", "r"); fscanf(fp, "%d", &rows); fclose(fp); if(iAtd > rows) { printf("Please enter a number <= %d\n", rows); exit(0); } k = 0; key = 1220; shmid = shmget(key, sizeof(int)*rows*columns, 0666); if(shmid < 0) { perror("shmget"); //Error out if shared mem not found exit(EXIT_FAILURE); } printf("Segment found\n"); matrix = (int *)shmat(shmid, 0, 0); //Attatch //printf("Shared mem\n"); //for(i = 0; i < rows; i++) //{ // printf("SHARED MEM\n%d\t%d\n", matrix[i*2 + 0], matrix[i*2 + 1]); //} while(1) { if(matrix[0*2 + 0] == 1) { //printf("SHARED MEM BEFORE\n"); //for(i = 0; i < rows; i++) //{ // printf("%d\t%d\n", matrix[(i+1)*2 + 0], matrix[(i+1)*2 + 1]); //} //printf("KILLING PIDs\n"); for(i = 0; i < iAtd; i++) { if(matrix[(i+1)*2 + 0] > 0) { printf("KILLING\t%d\n", matrix[(i+1)*2 + 0]); kill(matrix[(i+1)*2 + 0], SIGTERM); //Kills the process printf("KILLED\t%d\n", matrix[(i+1)*2 + 0]); matrix[0*2 + 1]--; } } for(j = 0; j < matrix[0*2 + 1]; j++) { matrix[(j + 1)*2 + 0] = matrix[(j + 2)*2 + 0]; } //printf("SHARED MEM AFTER\n"); //for(i = 0; i < rows; i++) //{ // printf("%d\t%d\n", matrix[(i+1)*2 + 0], matrix[(i+1)*2 + 1]); //} matrix[0*2 + 0] = 0; } else { sleep(1); } } exit(0); }
  • How to Upgrade Ghost

    General Computing ghost blog upgrade how to
    1
    2 Votes
    1 Posts
    492 Views
    ScuzzS
    Usually the upgrade process for various web based software is very simple. Enter a few commands over SSH, run a script or even upgrade via an admin control panel. Upgrading the Ghost blogging platform is very similar. In this post I will run you through a very quick way of upgrading Ghost to the latest version. How to Upgrade a Ghost Blog Before you upgrade any software it is always recommended to backup all your data. Luckily Ghost has a simple way of backing up. Log into your blog admin control panel and then go to Settings > Labs. Now click the export button. This will download a .JSON file. This file can be used to restore your blog. It is also recommended that you backup your images and theme in your \ghost\content\ directory. This can be done by logging into your server via FTP, SFTP or any other method of accessing your server for file transfers. SSH into your server CD \to\ghost\installation\folder wget http://allaboutghost.com/updateghost chmod +x updateghost ./updateghost The script will run and once it has finished you can now run ghost with your preferred method. At BitBangers we like to run our Ghost blog with Forever. So to get our blog up and running again we need to enter the following command. NODE_ENV=production forever start index.js If the script has run correctly you should have a fully update Ghost instance running. Below is the contents of the updateghost script. #!/bin/bash # Written by Andy Boutte and David Balderston of howtoinstallghost.com, ghostforbeginners.com and allaboutghost.com # updateghost.sh will update your current ghost install to the latest version without you losing any content if [ -f config.js ] then echo `whoami` # Make temporary directory and download latest Ghost. mkdir temp cd temp curl -L -O https://ghost.org/zip/ghost-latest.zip unzip *.zip cd .. # Make database backups. for file in content/data/*.db; do cp "$file" "${file}-backup-`date +%Y%m%d`"; done # Copy the new files over. yes | cp temp/*.md temp/*.js temp/*.json . rm -R core yes | cp -R temp/core . yes | cp -R temp/content/themes/casper content/themes npm install --production # Delete temp folder. rm -R temp echo "You can now start Ghost with npm, forever or whatever else you use." else echo "Please cd to your Ghost directory." fi Thanks to HowToInstallGhost for proving the script and instructions.
  • List of Python resources

    Development and Coding python learning resources
    5
    1 Votes
    5 Posts
    1k Views
    S
    @Scuzz They have an ebook version that looks good but I’ve not been able to find a download for it anywhere.
  • Offers from Google Play

    Tech
    2
    0 Votes
    2 Posts
    572 Views
    ScuzzS
    You get sweet deals with Chromecast too.
  • Show us your mobile battery stats!

    Tech battery phone mobile stats
    14
    0 Votes
    14 Posts
    2k Views
    ScuzzS
    Made some changes to what some apps can do and now it seems to run a lot longer than it did before. [image: qFv6nj5.png@30%25] [image: eePgyOc.png@30%25] I need to see how long it last without heavy usage. Maybe i could hit the 2 day mark.
  • Far Cry 4's Honey badgers are OP as fuck, and the game knows it.

    Gaming
    9
    2 Votes
    9 Posts
    1k Views
    SchamperS
    http://xboxclips.com/Schamper/787339a8-987a-4410-a196-55a2ef2c5cc7