This is now an actual repo:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -module(skicalc). | |
| -author("Ben James <[email protected]>"). | |
| -export([eval/1, conv/1]). | |
| % Valid terms to be evaluated here are binary trees represented as | |
| % two-element tuples. Leaves can be anything, and the atoms s, k and i | |
| % represent the symbols S, K and I in the calculus' alphabet. | |
| % For example, an operator to reverse two elements can be defined as: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://phrogz.net/SVG/convert_path_to_polygon.xhtml | |
| function pathToPolygon(path,samples){ | |
| if (!samples) samples = 0; | |
| var doc = path.ownerDocument; | |
| var poly = doc.createElementNS('http://www.w3.org/2000/svg','polygon'); | |
| // Put all path segments in a queue | |
| for (var segs=[],s=path.pathSegList,i=s.numberOfItems-1;i>=0;--i) segs[i] = s.getItem(i); | |
| var segments = segs.concat(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // create tab group | |
| var tabGroup = Titanium.UI.createTabGroup(); | |
| // | |
| // create base UI tab and root window | |
| // | |
| var win1 = Titanium.UI.createWindow({ | |
| title: 'Tab 1', | |
| backgroundColor: '#fff' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Perl and PHP Regular Expressions | |
| PHP regexes are based on the PCRE (Perl-Compatible Regular Expressions), so any regexp that works for one should be compatible with the other or any other language that makes use of the PCRE format. Here are some commonly needed regular expressions for both PHP and Perl. Each regex will be in string format and will include delimiters. | |
| All Major Credit Cards | |
| This regular expression will validate all major credit cards: American Express (Amex), Discover, Mastercard, and Visa. | |
| //All major credit cards regex | |
| '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$/' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (* Stand-alone Twitter API ServiceStack Web Service with F# on Mono/OSX hosted by HttpListener | |
| Instructions: | |
| 1) download https://github.com/ServiceStack/ServiceStack/downloads | |
| 2) fsharpc -r:ServiceStack.Common.dll -r:ServiceStack.Interfaces.dll -r:ServiceStack.Text.dll -r:ServiceStack.dll FTweetStack.fs | |
| 3) sudo mono FTweetStack.exe | |
| *) | |
| open System | |
| open ServiceStack.ServiceHost |
Wish you had some immutability in Javascript? Now you can!
var t = {a: 1, b: 2}.immutable();
console.log(t.a, t.b);
try {
t.a = 3; // -> Uncaught Error: a is immutable and cannot be modified.
} catch (e) {
console.log(e);
}
var t2 = t.copy({a: 3});
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using SharpKit.JavaScript; | |
| namespace PhantomJS | |
| { | |
| [JsType(JsMode.Prototype, Export = false, Name = "console")] | |
| public static class Console | |
| { | |
| public static void log(string message) {} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Lack of tail call optimization in JS | |
| var sum = function(x, y) { | |
| return y > 0 ? sum(x + 1, y - 1) : | |
| y < 0 ? sum(x - 1, y + 1) : | |
| x | |
| } | |
| sum(20, 100000) // => RangeError: Maximum call stack size exceeded | |
| // Using workaround |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tell application "Finder" | |
| try | |
| set appPath to (path to application "Evernote" as text) | |
| on error | |
| display dialog "Couldn't find Evernote. Is it installed?" | |
| end try | |
| set printPath to (path to "dlib" from user domain as text) & "PDF Services" | |
| make new alias at printPath to appPath with properties {name:"Send PDF to Evernote"} | |
| end tell |
OlderNewer