Sharing, reputation, and more


Published in: New Features, Site NewsPosted by thoaionline on 11/23/11


In the last few months, we have been enhancing the website with new features. Well, let’s just skip the introductory part and go straight to the cool stuffs.

Simplified login with Facebook connect

You can now login into Snipplr.com using your Facebook account. If you have been with Snipplr for a while, use the connect option in the Settings page. New to Snipplr? Just click “Login with Facebook” on the homepage and you’re ready to go!

More ways to share

Having saved a snippet of code that you are proud of? Talk about it! We’ve added the option to share your snippets on common social networks such as Facebook, Google+ and Twitter. Find a snippet that might be of interest to a friend? You can now send any snippet to your friend via Facebook private message, directly on the snippet page!

Show your support

We believe that there are times when you want to say thanks the author of the snippet that solves your problem. The “FAV” feature is back (confession: we had a JS error that prevented the feature from working). To mark a snippet as your favourite, click on the FAV icon next to its name, a snippet you like will be marked orange. Did we mention that you can “like” comments too?

Reputation system and badges

We believe that you should be recognised for your community contribution (remember that your snippet can be of great help to others). A reputation system was created to track your submission, views and favourites that others give you. You may have noticed the new homepage arrangement with an “achievement” column. We created a number of badges that you can show off from your profile page. We will soon implement a site-wide ranking system based on the score-based reputation, which is accessible from within your dashboard.

Popular snippets by month, week, and year

The website used to display all time popular snippets based on the number of likes on the homepage. This caused some of the very old snippets (some dated back in our first days) still sticking on the front-page. We consider the freshness of the snippets just as important as the number of “favourites”. For this reason, we now display the popular snippets based on both submission time and popularity. You can even filter the popular snippets to display only notable ones by time, programming language, and tag.


‘Tweet This’ Now Available


Published in: Site NewsPosted by Travis on 11/02/10


In case you hadn’t noticed, we’ve been slowing adding a few new features to Snipplr. Now on the bottom of each snippet you’ll see a little ‘Tweet’ icon. Simply click to tell the Twitter world about your snippet.

Tweet this area.

Also, you may have noticed that we’ve been running a few featured items from our sister site CodeCanyon. If anything catches your eye, be sure to head over to CodeCanyon to check out the details!

We’re going to be slowing adding features and improving the service over the next little while. While I can’t give you a firm date yet, it looks like we may be in for our redesign in the upcoming year. Huzzah!

Stay tuned for more details =)


iPhone Snippets on Mobiletuts+


Published in: News, Site NewsPosted by Travis on 09/16/10


I’m excited to announce that we’re going to be doing some snippet sharing with one of our sister sites Mobiletuts+.

Mobiletuts+ is a top level site for quality tutorials for mobile developers. Topics include native development with the iPhone, Android, Windows and Blackberry platforms, cross-platform development with tools like Appcelerator and Phone Gap, and techniques for building mobile accessible web sites with HTML 5.

This week they posted a quick screencast using one of the iPhone snippets found right here on Snipplr.

Be sure to check out their iOS SDK Snippet: iPhone Vibration tutorial and keep you eyes open for more to come.

Also, be sure to follow us on Twitter for more news and updates!


Video from the Chicago Meetup


Published in: News, Site NewsPosted by Travis on 09/09/10


In case you hadn’t heard, we just had our first ever Envato community meetup in Chicago. The atmosphere was fun and relaxed and we got to meet a ton of great people.

Adam Miller from Aetuts+ thought it would be a good idea to do some live streaming from the event. In Part 1 we all get a feel for it (and you get to see a lot of people’s backends), but in Part 2 things really get rolling.

Check out our Snipplr updates at about the three minute mark of Part 2 followed by a little question and answer with Collis.

Enjoy!

Introduction: Part 1

Q & A Time: Part 2


Link to Snipplr in Your Envato Profile


Published in: Site NewsPosted by Travis on 08/06/10


Snipplr Profile on Envato

I just got the good word that you can now link to your Snipplr account from your profile on any Envato site that supports cross-site profiles.

Just head over to your Envato site of choice and after you sign in go to My Account>MySettings>Social Network Links and add your Snipplr username.

It will be a great way to quickly link to any support code or to showcase your mad hacking skills. Head over and add your link!


Snipplr Snippets – WordPress Plugin


Published in: Plugins, Site NewsPosted by Travis on 07/05/10


The Snipplr Snippets WordPress plugin was recently updated and now works with WordPress 3.0.

If you’re not familiar with the plugin, it allows you to embed snippets directly into your Wordpress posts using the snippet ID.

Features include:

  • Code highlighting using GeSHi.
  • Sidebar widget to show your latest code snippets.
  • Easily embed snippets into the page using [snippet id=##]
  • Customisable layout using CSS. Can disable default plug-in CSS from the admin settings
  • Uninstall option in the plugin settings page.

Pick up the plugin now or head over to the author’s website for more information.


Snippets App – With Built in Snipplr Love


Published in: Site NewsPosted by Travis on 06/24/10


We just received an email from developer Vadim Shpakovski who informed us of Snippets, a Mac App that stores your valuable pieces of code so you can reuse them in different projects over and over.

That all sounds very tasty, but here’s the best part – it has built in Snipplr submission functionality. So you got to love that!

Head over to the Snippets website, or check out the page we just put together in our developers section and let us know what you think about it.


Lightweight IPv4


Published in: Development, Language, PHPPosted by Jdub7 on 08/03/09


Introduction

For a midsize project I wanted to store IP ranges in the database with the option to to also store CIDR blocks. CIDR blocks, though powerful are somewhat difficult for a typical user. Additional using them is not as precise for all ip ranges. There are a plethora of tools available on the internet that will do what I would like. However, incorporating these tools would not be practical. What I want is to mimic the functionality of these tools so that it can be easily imported into any of my projects. The most coveted tool for me would be to convert an IP range to a precise range of CIDR blocks. This required specific functionality not naturally provided in PHP.

  • Check for Valid Netmask
  • Check whether an IP address is within a CIDR block.
  • Take user input and a Netmask and make it into a valid CIDR block.
  • CIDR number into Netmask
  • Netmask to CIDR
  • Take an IP range and fit it into an exact range of CIDR blocks.

This presents some difficulty in that PHP’s network functions are not thorough enough. The revelation came when I realized that an IP address is merely a number. In fact the whole protocol is rooted in binary using very specific patterns. With that in mind I thought we could develop very light weight methods to solve our problem.

The Code

It is important to note that the methods provided are meant for IPv4 addresses only are only tested on a 32bit system. Also, I did not care to do much in the way of error checking, but doing so, like testing whether the CIDR number is unsigned and less than or equal to 32, should be trivial.

Though the solution I sought after would require PHP I didn’t limit myself to that language only. In fact the PHP code I found seemed inefficient. Most involved a number conversions or parsing the address using sprintf using loops and nested if statements. Indeed the most efficient code, which shouldn’t surprise most was in ANSI C. Bit Twiddling Hacks resource proved very useful.

About Binary

I am not attempting to teach binary math. Since the code does not “read like prose” a small amount of knowledge is required in order to understand the code. Some excellent resources are Wikipedia’s article on CIDR and PHP binary operators.


Joy Of Groovy


Published in: Development, Groovy, LanguagePosted by yighu on 07/29/09


In my work and my volunteer, I need to do a lot of scripting for all kinds of things such as system administration, data migration etc. I have used shell script, perl and many other tools on and off for a long time before. Scripting with Groovy brings me much joy and fun.

Groovy brings the full Java language and its own flavors to your finger tips while you are typing and thinking your tasks and you can do a lot of things very easily and much simpler than other scripting. Here I will put up a few examples that demonstrate a few tricks that can simplify a lot of daily scripting work:

  1. File Manipulation
  2. Configuration
  3. Database Access
  4. Logging

Suppose you want to create a file and put stuff in it. This is how you do it:

def file=new File(“test.txt”)

do this: file.append(“line 1\n”) file.append(“line 2\n”)

Now the file has 2 lines.

Later some where, you want to do something with the data in the file, for example email the data to some one, this is how you get the content for the file: def content=file.txt()

Suppose you want to write a method, for example log(String text). The log method basically append what ever text into a log file.

binding['writer']=new File(“log.txt”)

def log(String text){ writer.append(text+”\n”) }

Now suppose, instead of putting the log into a log file, I want to put the log into a database table for easy to search or may be for data warehousing purpose, you can easily change the above log method without touching the rest of your code.

def log(String text){ sql.execute(“insert into usertrace(id,description) value(?,?)”,[nextid(),text]) }

where nextid() is simply a method that return you the next id of table usertrace.

Now what is sql here? Before I talk sql, I need to touch the groovy configuration a bit.

The ConfigSlurper is a cool thing.

You might have been used to manipulate the java Property class which you need to load the property file and then use getter method to fetch the string property you want. The groovy way is much simpler.

In this code, MyConfig.groovy is a groovy class which contains name/value pairs, one of them is called sql like this:

sql=groovy.sql.Sql.newInstance(“jdbc:postgresql://localhost:5432/helloworld”,”username”,”password”,”org.postgresql.Driver”)

This is how you get the property sql.

binding['cfg']=new ConfigSlurper().parse(new File(‘MyConfig.groovy’).toURL()) binding['sql']=cfg.sql

Notice that the new variable sql is an object, not just a String as in Java Property file. Then you can execute the method of the object sql, like we did in the above log method.

Have fun so far! As you explore Groovy, you will discover them more.


Custom Error Constructors in JavaScript


Published in: JavaScript, UncategorizedPosted by Elijah Grey on


[Note to person reviewing this: You should make a JavaScript post category.]

Most of the time, the standard six native error constructors and the one generic error constructor are not specific enough for an error. What if you want your library to throw a custom SecurityError if it detects an XSS vector on a website? I made a function to create such constructors that behave the exact same way the native error constructors, like SyntaxError by using methods like Error.prototype.toString and the standard error object format. This code makes throwing a custom fake error constructor made with ErrorConstructor("SyntaxError") have the same output as a native SyntaxError in a JavaScript shell. I’ve tested the code in Firefox 3/3.5 and Opera 9.6 and it seems to work fine. Comment and say if it works in your browser too.

function ErrorConstructor(constructorName) {
  var errorConstructor = function(message, fileName, lineNumber) {
  // don't directly name this function, .name is used by Error.prototype.toString
    if (this == window) return new arguments.callee(message, fileName, lineNumber);
    this.name = errorConstructor.name;
    this.message = message||"";
    this.fileName = fileName||location.href;
    if (!isNaN(+lineNumber)) this.lineNumber = +lineNumber;
    else this.lineNumber = 1;
  }
  errorConstructor.name = constructorName||Error.prototype.name;
  errorConstructor.prototype.toString = Error.prototype.toString;

  return errorConstructor;
}

Usage: ErrorConstructor([constructorName])

Note: If no constructorName is specified, the default of Error.prototype.name is used

Usage for generated error constructor: errorConstructor([message[, location[, lineNumber]])

Examples:

var SecurityError = ErrorConstructor("Security Error"),
MarkupError = ErrorConstructor("(X)HTML Markup Error");
//these will both throw a SecurityError starting with "Security Error on line 83:"
var xss_error = "Possible XSS Vector\n\
 JSON XHR response parsed with eval()\n\
 Recommended fix: Parse JSON with JSON.parse";
throw new SecurityError(xss_error, "/js/searchResultsJSONloader.js", 83);
throw SecurityError(xss_error, "/js/searchResultsJSONloader.js", 83);
//these will both throw the following MarkupError:
//"(X)HTML Markup Error on line 1: Invalid DOCTYPE"
throw new MarkupError("Invalid DOCTYPE");
throw MarkupError("Invalid DOCTYPE");