• First bit of Python in a long time

    4
    4 Posts
    181 Views
    AlmostA
    Maybe they expected you to do two passes? def satisfiesF(L): x = [] for item in L: if f(item): x.append(item) for item in x: L.remove(item) return len(L) Seems like a bad question to me. If we’re going with the second interpretation (where you return a new list) I think this would work: def satisfiesF(L): return [x for x in L if f(x)]
  • [nodebb-theme-classic] BitBangers Classic Theme

    nodebb theme
    13
    13 Posts
    2k Views
    ScuzzS
    Here is all the css i have currently in the admin control panel. There are some changes I have made directly to some files. I think these changes are only background color and @brand-primary. body { background: #f0f0f0; color: #888; } .shoutbox blockquote { padding: 5px; margin: 0px; font-size: medium; } .shoutbox .img-responsive { max-width: 200px; } .shoutbox-content { height: 250px; } .col-xs-12 { padding-left: 0px; padding-right: 0px; } .navbar-default { background-color: #dc3522; } .navbar-default .navbar-nav>li>a { color: #FFF; } .navbar-default .btn-link { color: #FFF; } .navbar-default .navbar-toggle .icon-bar { background-color: #FFF; } .navbar-default .navbar-toggle { border-color: #FFF; } .navbar-default .navbar-toggle:hover { background-color: #bd2e1d; } .row { margin-left: 0px; margin-right: 0px; } #nprogress .bar { background: #FFF; } #nprogress .spinner-icon { border-top-color: #FFF; border-left-color: #FFF; } .categories>li, .category>ul>li { padding: 20px; background: #FFF; border: 1px solid #e2e2e2; margin-bottom: 20px; -webkit-box-shadow: 0 0px 2px rgba(0, 0, 0, 0.1); -webkit-border-radius: 3px; overflow: hidden; } .categories-title { display: none; } .categories>li .card, .category>ul>li .card { border-left: 1px solid #e2e2e2; } .category>ul>li:not(.unread) h2 a { color: #dc3522 !important; } .category>ul>li:not(.unread) h2 a:hover { color: #bd2e1d !important; } .topic h1 { display: none; } .topic .posts>li { background: #FFF; border: 1px solid #e2e2e2; padding: 20px; margin-bottom: 20px; -webkit-box-shadow: 0 0px 2px rgba(0, 0, 0, 0.1); -webkit-border-radius: 3px; } .account .profile { background: #FFF; border: 1px solid #e2e2e2; padding: 20px; margin-bottom: 20px; -webkit-box-shadow: 0 0px 2px rgba(0, 0, 0, 0.1); -webkit-border-radius: 3px; } .posts-list { background: #FFF; border: 1px solid #e2e2e2; padding: 20px; margin-bottom: 20px; -webkit-box-shadow: 0 0px 2px rgba(0, 0, 0, 0.1); -webkit-border-radius: 3px; } .users-container { background: #FFF; border: 1px solid #e2e2e2; padding: 20px; margin-bottom: 20px; -webkit-box-shadow: 0 0px 2px rgba(0, 0, 0, 0.1); -webkit-border-radius: 3px; } .btn-primary { background-color: #dc3522; border-color: #dc3522; } .btn-primary:hover { background-color: #bd2e1d; border-color: #bd2e1d; } .btn-primary:focus { background-color: #bd2e1d; border-color: #bd2e1d; } .fab { background-color: #dc3522; } a { color: #dc3522; } a:hover { color: #bd2e1d; } .pagination>li>a, .pagination>li>span { color: #dc3522; } .pagination>.active>a, .pagination>.active>span, .pagination>.active>a:hover, .pagination>.active>span:hover, .pagination>.active>a:focus, .pagination>.active>span:focus { background-color: #dc3522; border-color: #dc3522; } .pagination>li>a:hover, .pagination>li>span:hover, .pagination>li>a:focus, .pagination>li>span:focus { color: #bd2e1d; }
  • [Python] Twitter controlled LEDs

    python twitter led arduino
    8
    8 Posts
    1k Views
    SchamperS
    I did something similar back with Boblight a year or 2 ago. Had it working with configurable lighting effects and Facebook/Email too. https://www.youtube.com/watch?v=RM946iXWEx8 The lighting transition was generated as well since Boblight only took byte streams and didn’t know about any effects. Kind of related to this, I currently have my Hyperion set up with 2 different sources, Kodi and an USB video grabber but I needed a way to easily switch them. My first solution was to create a Kodi plugin that I could control using a simple HTTP request. It worked but was tedious. I recently learned about the existence of cec-client and it’s monitoring mode, so I whipped up a bash script that monitors the CEC traffic and changes Hyperion sources based on my AV receiver’s source. All configurable too. The only other thing I want now is to be able to change the HDMI OUT mode of my receiver but apparently that’s impossible using CEC. There’s an undocumented command you can send over telnet to do it though but I don’t want to get another ethernet cable there.
  • I made an 8-ball

    2
    2 Posts
    535 Views
    FireladF
    Saw this and I had to play around with it. Here’s results: [image: AcdGDS4.png] [image: 18gm70f.png] Turns out I’m not gay… LOL
  • [Challenge] BB Gets Drunk

    3
    3 Posts
    566 Views
    AlmostA
    Really minor improvement, but in order to remove that extra if (numStillWanted > 0) we could consider any alcohol that we don’t have as inventory that belongs to no one. To make this work in the code, we just add a line outside the outer loop: have = have.concat(wanted.select(cur => new AlcoholInventoryItem(null, cur.Name, cur.Quantity)); With this, we’re assured that we will never be left with numStillWanted > 0 after the inner loop because in the case where no one has any of the alcohol we want, our inventory consists of alcohol that belongs to no one that has exactly the quantity we want.
  • [nodebb-plugin-imdb] IMDB Information

    nodebb imdb plugin
    14
    14 Posts
    2k Views
    AlmostA
    Look at you getting things to work! Nice job.
  • A Brief Introduction to Haskell

    haskell
    1
    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

    14
    14 Posts
    2k Views
    ScuzzS
    Any updates on this @schamper?
  • [C] Printer queue emulation with child processes

    printe queue
    1
    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); }
  • List of Python resources

    python learning resources
    5
    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.
  • Browser Pong

    programming pong game
    2
    2 Posts
    912 Views
    AntuA
    I set the source public yesterday on Github and MDN in case anyone is interested in it. I’m going to take a break for the holidays, and start work on some new projects next year. See you.
  • Blog post for my internship

    internship blog
    1
    1 Posts
    541 Views
    SchamperS
    My boss kept nagging me to make a short blog post about my internship project, so I did. Some of you might know that I’m having trouble getting feedback on my work, so I put in some comments about that in this post. Android application development I’ve been working on the Projectcampus Android application since September, and I must say I’ve learned a lot about Android and personally think the application is coming along nicely. ​​​It all started as a very simple list of hardcoded data, but gradually grew to make use of various Android components such as a Content Provider, Authenticator, Sync Adapter and even custom views. Besides these components I’ve learned about using various mainstream libraries such as Retrofit, OkHttp, Glide, Butterknife, Eventbus, Crashlytics and the Android Support Library. ​ Retrofit powers the REST communication with the Projectcampus backend in combination with EventBus. EventBus is exactly what it sounds like, an event bus. This makes it possible to launch a REST request from anywhere in the application and also to allow any part of the application to receive any REST response. EventBus is also used for other inner-application communication. Glide is an image loading and caching library used for the various images used throughout the application. All of the networking is backed by OkHttp.​ Butterknife is a view “injection” library for Android and is used to reduce the amount of boilerplate code. Crashlytics is used to report crashes and errors. The Android Support Library is used for a couple of things like Material support for API levels below 21, Toolbar and new Swipe Refresh Layout. ​ In the current structure, all REST request events are handled by a Retrofit client. This client posts all the results to the event bus. A database service listens to all the response events and writes these to the database through a content provider. Any fragment or activity subscribed to the affected URI’s will be automatically updated through the magic of cursor loaders. ​ I’ve also made sure to improve performance where I can. Making use of the View holder pattern, reducing layout XML complexity and depth and reducing overdraw are a few examples I can currently think of. I’m sure there are parts in my code that can be refactored to be more performant, but that’s hard to determine when you’re the only person looking at the code. ​ The application is also configurable at build time using gradle. There are several properties that can be set to configure the application, most important being the URLs and client ID for the API. There are also properties to disable certain features of the application. ​ All in all I’m fairly happy with the current state of the application. However, I also feel like it could be a lot better and further along if I had occasional feedback. A very large portion of my time has been spend redoing something I did the previous week. On the other hand, I’m also kind of proud of myself that I’ve managed to put together the application in its current state all by myself. [image: iqFWO8C.png]
  • WIIIS (Nintendo Wii Image Search)

    image wii c++ search
    1
    1 Posts
    496 Views
    ScuzzS
    WIIIS (Nintendo Wii Image Search) As computer games consoles become more and more like computers the need for forensic investigation methodologies and software also increases. Many new games console have hard drives that are able to store images, films and music on them and because of this they can be used to store illegal content. Games console can also be modified to run homebrew applications that give access to hidden areas of the storage of the games console, adding further hiding places for illegal files. This report describes different consoles and their method of modification and the implementation of an image carver for two games consoles. The Nintendo Wii Image Search will search for .jpg files stored on an external SD card and display their location on screen. WIIIS requires the homebrew channel to be installed on the Nintendo Wii console #include <iostream> #include <string> #include <vector> #include <gccore.h> #include <wiiuse/wpad.h> #include <fat.h> #include <dirent.h> using namespace std; static void *xfb = NULL; static GXRModeObj *rmode = NULL; void initVideo() { VIDEO_Init(); WPAD_Init(); rmode = VIDEO_GetPreferredMode(NULL); xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); VIDEO_Configure(rmode); VIDEO_SetNextFramebuffer(xfb); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); cout << "\x1b[2;0H"; } int initFat() { if(!fatInitDefault()) { cout << "Unable to initialise FAT, exiting.\n"; return 1; } DIR *dir; dir = opendir("/"); if(!dir) { cout << "Failed to open dir, exiting.\n"; return 1; } closedir(dir); return 0; } void searchDir(string &rootDir, vector<string> &files) { string filePath; DIR *dir; struct dirent *entry; struct stat statbuf; dir = opendir(rootDir.c_str()); while((entry=readdir(dir)) != 0) { stat(entry->d_name, &statbuf); if(entry->d_name[0] != '.') { filePath.erase(); filePath = rootDir + string(entry->d_name) + "/"; if(S_ISDIR(statbuf.st_mode)) { searchDir(filePath, files); } if(string(entry->d_name).length() > 3) { if(string(entry->d_name).substr(string(entry->d_name).length() - 3, 3) == "jpg") { files.push_back(filePath.substr(0, filePath.size() - 1)); } } } } closedir(dir); } int main(int argc, char **argv) { vector<string> files; initVideo(); initFat(); string rootDir = "/"; cout << "Wii Image Search, press A to start or Home to quit.\n"; while(1) { WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); if(pressed & WPAD_BUTTON_HOME) { return 0; } if(pressed & WPAD_BUTTON_A) { searchDir(rootDir, files); for(std::vector<string>::const_iterator i = files.begin(); i != files.end(); ++i) { cout << *i << "\n"; } } VIDEO_WaitVSync(); } return 0; }
  • Some Encryption program in Python

    python enryption
    1
    1 Posts
    846 Views
    ScuzzS
    Encryption program for a university module Usage: python joshcrypt.py [-h] [-e] [-d] keyword inputFile outputFile Flags: [-h] Help. This flag will generate help from the command line. [-e] Encrypt. Use this flag to encrypt the inputFile. [-d] Decrypt. Use this flag to decrypt the inputFile. Arguments: Keyword - The keyword used to encrypt the file. inputFile - The Filename to save the encrypted/decrypted file as. This program needs to be run from the command line; cmd.exe or any terminal emulator will suffice. To start the encryption process a user must type: python joshcrypt.py -e "keyword" "inputfile" "outputfile" Keyword is the password used for the document. Inputfile is the file that you want to be encrypted. Outputfile is the file that you want the encrypted file to be saved as. To start the decryption process a user must type: python joshcrypt.py -d "keyword" "inputfile" "outputfile" Keyword is the password used for the document. Inputfile is the file that you want to be decrypted. Outputfile is the file that you want the plain text file to be saved as. # Requires Python 2.7 as Python 3.0+ contains bugs with the array.array() function. import argparse import array import sys # Opens file as a byte array. def getBlock(fileName): f = open(fileName, "rb") blockArray = array.array('b', f.read()) f.close return blockArray # Converts bytes to string and writes it to a file. def writeBlocks(blocks, fileName): f = open(fileName, "wb") string = blocks.tostring() f.write(blocks) f.close() # Generates a key. # Converts the key into a byte array, creates another byte array of the key but reversed. # Xor the bytes together to generate the final key. def genKey(key): a = array.array('b', key) b = a[::-1] for x in range(len(a)): a[x] = a[x] ^ b[x] return a # Xor the bytes of the key with the bytes of the file. # Loops through the key and adds the times it has looped to the end of the key def encrypt(blocks, key): i = 0 r = 0 for block in range(len(blocks)): blocks[block] = blocks[block] ^ key[i] if i == len(key) - 1: i = 0 r += 1 key = genKey(key.tostring() + str(r)) else: i += 1 return blocks def decrypt(blocks, key): i = 0 r = 0 for block in range(len(blocks)): blocks[block] = blocks[block] ^ key[i] if i == len(key) - 1: i = 0 r += 1 key = genKey(key.tostring() + str(r)) else: i += 1 return blocks # Sets up the command line arguments # Calls functions to encrypt the file. def main(): parser = argparse.ArgumentParser(description="Encrypt and Decrypt a file.") parser.add_argument("-e", action = "store_true", default = False, dest = "edFlag", help = "Encrypt File") parser.add_argument("-d", action = "store_false", default = False, dest = "edFlag", help = "Decrypt File") parser.add_argument("keyword", action = "store", help = "Keyword used to encrypt or decrypt file") parser.add_argument("inputFile", action = "store", help = "Filename to be encrypted/decrypted") parser.add_argument("outputFile", action = "store", help = "Filename to save the encrypted/decrypted file as") args = parser.parse_args() if len(args.keyword) < 10 or len(args.keyword) > 40: print "Password needs to be greater than 10 characters and less than 40" sys.exit(1) if args.edFlag: print "ENCRYPTING" key = genKey(args.keyword) blocks = getBlock(args.inputFile) encrypted = encrypt(blocks, key) writeBlocks(encrypted, args.outputFile) else: print "DECRYPTING" key = genKey(args.keyword) blocks = getBlock(args.inputFile) decrypted = decrypt(blocks, key) writeBlocks(decrypted, args.outputFile) if __name__ == '__main__': main()```
  • PS3 Image Searcher (C++)

    ps3 image search c++
    1
    1 Posts
    470 Views
    ScuzzS
    Here is a project I did for my final year at uni. It is a homebrew program for the PS3 that will let you search for images files on the HDD and then transfer them to USB. It’s probably buggy as hell and it only searches for file extension and the copy function is stupidly slow but it did work. It’s coded in C++ with some graphic library i found for the PS3. I can’t remember what it is. #include <NoRSX.h> #include <sys/stat.h> #include <sys/file.h> #include <fstream> #include <iostream> #include <string.h> #include <vector> #include <sysmodule/sysmodule.h> #include <io/pad.h> using namespace std; static NoRSX *GFX; string detectUSB() { int fd; string USB = ""; int usbNum = 0; char path [256]; for(usbNum = 0; usbNum < 11; usbNum++) { sprintf(path, "/dev_usb00%d/", usbNum); if(sysLv2FsOpenDir(path, &fd) == 0) { USB = string(path); } } return USB; } void searchDir(string rootDir, vector<string> &fileNames) { sysFSDirent entry; s32 fd; u64 read; string filePath; if(sysLv2FsOpenDir(rootDir.c_str(), &fd) == 0) { sysLv2FsOpenDir(rootDir.c_str(), &fd); while(!sysLv2FsReadDir(fd,&entry,&read) && strlen(entry.d_name)>0) { if(entry.d_name[0] != '.') { if(entry.d_type == 0x01) { GFX->Flip(); filePath.erase(); filePath = rootDir + string(entry.d_name) + "/"; searchDir(filePath, fileNames); } else { if(string(entry.d_name).substr(string(entry.d_name).length() - 3, 3) == "jpg") { fileNames.push_back(rootDir.substr(0, rootDir.size()) + string(entry.d_name)); } } } } sysLv2FsCloseDir(fd); } } void copyFiles(string destDir, vector<string> files) { string destFilePath = ""; string origFilePath = ""; for(std::vector<string>::const_iterator i = files.begin(); i != files.end(); i++) { origFilePath = *i; destFilePath = destDir + origFilePath.substr(origFilePath.find_last_of("/") + 1); ifstream origFile(origFilePath.c_str()); ofstream destFile(destFilePath.c_str()); destFile << origFile.rdbuf(); } } s32 main(s32 argc, const char* argv[]) { padInfo padinfo; padData paddata; ioPadInit(7); GFX = new NoRSX(); Font F(JPN, GFX); Bitmap BMap(GFX); NoRSX_Bitmap Precalculated_Layer; BMap.GenerateBitmap(&Precalculated_Layer); vector<string> files; int debug = 0; string USBStatus = ""; string HDDStatus = ""; string USBFiles = ""; string HDDFiles = ""; string test = ""; int ImagesFound = 160; F.PrintfToBitmap(100,80,&Precalculated_Layer,COLOR_RED,15,"PS3 Image Search, Press X to start or START to quit"); GFX->AppStart(); while(GFX->GetAppStatus()) { ioPadGetInfo(&padinfo); for(int i = 0; i < MAX_PORT_NUM; i++) { if(padinfo.status[i]) { ioPadGetData(i, &paddata); if(paddata.BTN_START) { GFX->AppExit(); } if(paddata.BTN_CROSS) { HDDStatus = "/dev_hdd0/Forensic/"; searchDir("/dev_hdd0/Forensic/", files); for(std::vector<string>::const_iterator i = files.begin(); i != files.end(); ++i) { BMap.DrawBitmap(&Precalculated_Layer); HDDFiles = "File: " + *i; F.PrintfToBitmap(600,ImagesFound,&Precalculated_Layer,COLOR_WHITE,15,"HDD Files: %s", HDDFiles.c_str()); GFX->Flip(); ImagesFound = ImagesFound + 20; } USBStatus = "No USB"; USBFiles = ""; if(detectUSB() != "") { USBStatus = detectUSB(); copyFiles(USBStatus, files); } } } } BMap.DrawBitmap(&Precalculated_Layer); F.Printf(100,100,COLOR_WHITE,15,"USB Status: %s", USBStatus.c_str()); F.Printf(100,120,COLOR_WHITE,15,"USB Files: %s", USBFiles.c_str()); F.Printf(100,140,COLOR_WHITE,15,"HDD Status: %s", HDDStatus.c_str()); F.Printf(100,160,COLOR_WHITE,15,"HDD Files: %s", HDDFiles.c_str()); F.Printf(100,180,COLOR_WHITE,15,"Images Found: %d", ImagesFound); F.Printf(100,200,COLOR_RED,15,"DEBUG: %d", debug); GFX->Flip(); debug++; } BMap.ClearBitmap(&Precalculated_Layer); GFX->NoRSX_Exit(); ioPadEnd(); return 0; }
  • nodebb-plugin-butt

    nodebb plugin
    1
    1 Posts
    618 Views
    SchamperS
    About In protest of the removal of all my contest entries I have made a new plugin! I’m sure you are familiar with the cloud -> butt extensions for basically all major browsers out there… Well now there’s a NodeBB plugin for it as well! Bonus: you can even customize what words to change to butt in the ACP! Installation npm install nodebb-plugin-butt Source Github
  • NodeBB Hiccups

    nodebb hiccup
    4
    4 Posts
    982 Views
    SchamperS
    Btw npm link still works fine.
  • nodebb-plugin-anchors

    nodebb plugin anchors
    2
    2 Posts
    1k Views
    J
    Woo hoo! Do you want to be included in the plugin contest? :smile:
  • nodebb-plugin-image-sizer

    nodebb plug image sizer
    1
    1 Posts
    839 Views
    AlmostA
    I made a plugin so that you can resize images in markdown specifically because of this thread. The syntax is based loosely on the way iOS handles multple image sizes combined with normal markdown image embedding: ![alt text](http://someurl.com/someimage.png@<size> Size can take the following formats: 100x200 - Absolute size 100x x200 - Absolute size where the other dimension is calculated to maintain aspect ratio 50% - Percentage 0.5 - Scalar Multiplier So for example, my original picture: http://cl.ly/image/2L3F1M2E1X3l/IMG_0136.JPG is 1000x750. All of the following would produce the same image at 1/2 size: [white house](http://cl.ly/image/2L3F1M2E1X3l/IMG_0136.JPG@500x375) [white house](http://cl.ly/image/2L3F1M2E1X3l/IMG_0136.JPG@500x) [white house](http://cl.ly/image/2L3F1M2E1X3l/IMG_0136.JPG@x375) [white house](http://cl.ly/image/2L3F1M2E1X3l/IMG_0136.JPG@50%) [white house](http://cl.ly/image/2L3F1M2E1X3l/[email protected]) Install via npm: npm install nodebb-plugin-image-sizer Source: https://github.com/Kern--/nodebb-plugin-image-sizer Known Issues: Images that are set to be wider than their container become elongated (width is set to match the container, but height is not adjusted). This means that mobile can get a bit dicey.
  • Ambilight with Raspberry Pi and Hyperion

    ambilight raspberry hyperion arduino
    11
    11 Posts
    2k Views
    SchamperS
    @Scuzz From what I’ve read, you get the best effect by having them point at the wall at like a 45 degree angle. I’ve seen a lot of PVC pipe structures where you can easily adjust the angle.
Online Users