archive-us.com » US » N » NJL.US

Total: 26

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • NJL Heavy Industries, LLC
    Learning to Make Hacker News Readable Again you need to scrape articles off of Hacker News so you have a set of data to start doing machine learning with So I went ahead and cleaned up and published HNScrape a library that will fetch the first two pages from Hacker News and return a list of the articles as an array of objects The README on github has more details

    Original URL path: http://www.njl.us/code/hackernews-scraper/ (2016-04-27)
    Open archived version from archive


  • NJL Heavy Industries, LLC
    a surface creating a collection of self similar whorls and patterns Ken Perlin developed this in the late 80 s and it s important enough in computer animation that they gave him an Academy Award for it The use in web design should be obvious Instead of downloading a bunch of poorly compressed subtly textured background images most modern browsers can just download twelve kilobytes of Javascript and do the work themselves The plugin should also speed up the development process as design changes become a matter of just tweaking some parameters in Javascript This library only works on browsers that support the canvas element and even then really large tile sizes will break under IE 9 To handle this the library can load an optional background image when attempts to render the noise fail More advanced applications of Perlin noise involving iterative application of the results as well as three and four dimensional renderings that can be used to create animated sequences are left as an exercise to the reader I consider myself neither a Javascript expert nor a graphics expert and I wrote this code specifically to take me just a little bit out of my comfort zone

    Original URL path: http://www.njl.us/code/jquery-perlin/ (2016-04-27)
    Open archived version from archive

  • NJL Heavy Industries, LLC
    make your copy of Postfix drop all email into one mailbox do the following Create a file called etc postfix virtual replacing username with your desired delivery target USERNAME Next create a file called etc postfix virtual domains with the single line MATCH run postmap to compile these two files postmap etc postfix virtual postmap etc postfix virtual domains You then need to add or change the following two lines

    Original URL path: http://www.njl.us/code/making-postfix-accept-all-mail-and-stick-it-in-one-inbox/ (2016-04-27)
    Open archived version from archive

  • It's Dangerous Introduction
    sign bob example com print signed bob example com XqNmXBq1uGLgEKRqboqoifbbgeE s unsign signed bob example com fake malory example com lsdflashdfalsdkhfsadf try s unsign fake except itsdangerous BadSignature as e print e Signature lsdflashdfalsdkhfsadf does not match from itsdangerous import TimestampSigner s TimestampSigner SECRET KEY signed s sign This Thing print signed This Thing CNNEZA RhnQmEVTMSFzo9aaZrM07kFHRus s unsign signed max age 60 60 This Thing try s unsign signed max age 60 60 except itsdangerous SignatureExpired as e print e Signature age 4051 3600 seconds from itsdangerous import Serializer s Serializer SECRET KEY signed s dumps email example example com points 273 print signed points 273 email example example com gd WocjMM0A5zi6UJxbevhiOc5A s loads signed u points 273 u email u example example com Signer TimestampSigner Serializer TimedSerializer URLSafeSerializer URLSafeTimedSerializer from itsdangerous import URLSafeTimedSerializer s URLSafeTimedSerializer SECRET KEY salt password reset signed s dumps id 123 email bob example com signed eyJpZCI6MTIzLCJlbWFpbCI6ImJvYkBleGFtcGxlLmNvbSJ9 CN 8uViLlNMMBw s loads signed max age 24 60 60 u id 123 u email u bob example com salt is a namespace Be Very Careful Things are signed not encrypted Tamper Proof and Transparent The key is crucial to the whole thing bcrypt The Only Other Crypto

    Original URL path: http://www.njl.us/talks/itsdangerous_intro/ (2016-04-27)
    Open archived version from archive

  • Introduction to Flask
    Name form endif body html ls l rwxr xr x 1 n staff 197 Mar 23 19 40 hello world two py drwxr xr x 2 n staff 68 Mar 24 18 51 static drwxr xr x 5 n staff 170 Mar 23 19 55 templates Template Hello World usr bin env python from flask import Flask render template request app Flask name app route def splash user request values get user return render template hello html user user if name main app run debug True port 4002 Some Tests from hello world two import app def test splash page client app test client response client get assert response status code 200 assert form in response data def test name submission client app test client for name in u Ned u u2603 response client get u user format name assert response status code 200 data response data decode utf8 assert u Hello in data assert name replace e 3 in data assert form not in response data Thread Local Proxies from flask import request session from flask import g current app request form Form values request args Query string request values Combined request data Raw form data request files request headers request path url script root base url url root request get json app secret key SOMETHING LONG AND RANDOM session key value tricky session thing other thing new value session modified True session new session modified session permanent app before request def decorate request uid session get user id if uid g user some function uid else g user None Flash Hello World usr bin env python from flask import Flask render template request flash url for redirect app Flask name app secret key Something unique and secret app route def splash return render template flash html app route methods POST def add name user request form get user flash Hello format user return redirect url for splash if name main app run debug True port 4003 DOCTYPE html html head title Hello title head body with messages get flashed messages if messages for msg in messages h1 msg h1 endfor endif endwith form method POST input name user placeholder Your Name form body html Wall Application Some Logic import redis json r redis Redis MAX LENGTH 20 KEY MESSAGES def add message user msg r lpush KEY json dumps dict user user msg msg r ltrim KEY 0 MAX LENGTH 1 def get messages rv json loads x for x in r lrange KEY 0 1 return rv app Flask name app secret key SOMETHING LONG AND RANDOM app route def splash msgs logic get messages return render template home html msgs msgs app route login methods POST def login session user request values get user A Non return redirect url for splash app route add post methods POST def add post msg request values get msg logic add message session user msg return redirect url for splash DOCTYPE html html head head body ul for msg in

    Original URL path: http://www.njl.us/talks/intro_to_flask/ (2016-04-27)
    Open archived version from archive

  • Maps, Sets, and Graphs
    value def resize self length new array None length for entry in self entries if not entry continue if not insert into array entry 0 entry 1 new array return False self entries new array return True def get self key default None index calculate index key self entries if self entries index and self entries index 0 key return self entries index 1 return default def member self key index calculate index key self entries val self entries index return val and val 0 key def keys self return x 0 for x in self entries if x def values self return x 1 for x in self entries if x def items self return x for x in self entries if x Insertion O 1 except when it isn t Lookup O 1 Deletion O 1 Membership O 1 Different Implementations Different Tradeoffs Everything O lg n for example linked lists at nodes There is no ordering but OrderedDict provides an implementation that preserves insertion order Keys can t change in a way that would chnage the hash foo foo a 1 7 Traceback most recent call last File stdin line 1 in module TypeError unhashable type dict Sets Bags Caffeinatrix things which are awesome set python dogs fire cats python in things which are awesome ones set 1 1 1 1 1 len ones 1 some primes set 2 3 5 7 11 7 in some primes my things set cat dog shoes wombat your things set dog shoes rutabaga our things my things intersection your things deduplicated list set my list with duplicates A Dictionary With Just Keys Easiest Implementation class MySet object def init self args self values MyHash for k in args self add k def add self k self values add k None def values self return self values keys def member self k return self values member k def issubset self other for k in self values if not other member k return False return True a MySet 1 2 3 b MySet 1 2 3 4 5 assert not b issubset a assert a issubset b def intersection self other rv MySet for k in self values if other member k rv add k return rv a MySet 1 2 3 b MySet 2 3 4 5 assert a intersection b MySet 2 3 def union self other rv MySet for k in self values rv add k for k in other values rv add k return rv a MySet 1 2 3 4 b MySet 3 4 5 6 assert a union b MySet 1 2 3 4 5 6 def difference self other rv MySet for k in self values if other member k continue rv add k return rv a MySet 1 2 3 4 b MySet 2 4 5 assert a difference b MySet 1 3 Most of these are O n ish issubset issuperset union intersection difference symmetric difference Graphs MATH There can be lots of

    Original URL path: http://www.njl.us/talks/maps_sets_and_graphs/ (2016-04-27)
    Open archived version from archive

  • Cheap Helicopters In My Living Room
    for us Arduinos Atmel ATMEGA328 chip has digital analog I O can talk over serial a little bit of flash a little bit of RAM etc etc etc This is a full little 8 bit computer on a chip you can buy for less than 5 An Arduino Uno is 30 on Amazon You should order one of these too The arduino is all the support stuff the usb connection some headers assorted things to deal with power and a reset button int led 13 void setup pinMode led OUTPUT void loop digitalWrite led HIGH delay 1000 digitalWrite led LOW delay 1000 Kinda the canonical Arduino program setup is called after the reset button or power is brought on then loop is run in a loop This environment is to help ease people who don t really program into hacking away with this simplified language instead of figuring out a C tool chain yum9me int led 13 void setup pinMode led OUTPUT Serial begin 9600 void serialEvent byte in Serial read if in 0 digitalWrite led LOW else if in 1 digitalWrite led HIGH void loop delay 1000 import serial time s serial Serial dev tty usbmodem1421 9600 while True s write 1 time sleep 1 s write 0 time sleep 1 pip install pyserial Martin Bircher Martin Kenny Tudor Barker byte cmds 63 63 0 63 yaw pitch throttle trim void setup pinMode LED OUTPUT digitalWrite LED HIGH Serial begin 9600 void serialEvent if Serial available 4 return for int i 0 i byte sendPacket byte cmds Blinks LED returns time to sleep void loop delay sendPacket cmds class Heli object def init self path x for x in os listdir dev if x startswith tty usb 0 path dev path self s serial Serial path 9600 self yaw

    Original URL path: http://www.njl.us/talks/helicopters_in_my_living_room/ (2016-04-27)
    Open archived version from archive

  • Enough Machine Learning to Make Hacker News Readable Again
    grid search import GridSearchCV params svm C 0 5 1 0 2 0 4 0 svm loss l1 l2 hv ngram range 1 1 1 2 gs GridSearchCV p params verbose 2 n jobs 1 gs gs fit X y This does cross fold validation tries out all the different possible combinations of hyper parameters and spits out something you can pickle and do predict with in the future I love this so much I wrote pipelines of pipelines so I can try out all the possibilities Functions You ll See a Lot Of transform fit predict transform X y hv HashingVectorizer hv transform Simple is better than complex Sparse is better than dense with 10 stored elements Turn some input data into some other kind of input data Turn a dict or blob of text into a numpy array fit X y svm LinearSVC svm svm fit X y Train my model based on this input and these values Obvious for a classifier but can also have relevance for feature transforms or extractors or whatnot predict X y predictions svm predict X new Simple enough guess the Y Dealing with the Super Messy Real World Get the Data requests lxml Requests and lxml to the win I stuck stuff in Mongo because I m lazy I grab the entire linked content of the articles Be careful people will amaze you with how junky links are Worry about too big bad https certificate etc Classify Dreck and Non Dreck I don t want to read about negativity bitcoins your incredibly lame business hacks or world news Bring the pain would feed me a continuous sequence of iframed hacker news articles to classify until I wanted to cry Over five thousand articles 18 not dreck Title URL Submitter Content of Link Rank Votes Comments Time of Day Dreck or Not Messy Data to Normalized Numpy Arrays All of the classifiers take numpy arrays They usually work best when all of the input numbers are scaled together into similar ranges Bag Of Words n grams Normalization Stop Words TF IDF Bag of Words Time Flies Like An Arrow Fruit Flies Like Bananas Flies 2 Like 2 Time 1 An 1 Arrow 1 Fruit 1 Bananas 1 Bitcoin 0 Pretty literal just forget about that messy grammar just worry about word presence or count n grams Time Flies Like An Arrow Fruit Flies Like Bananas Time Flies Flies Like Like An An Arrow Arrow Fruit Group the words alone unigram or pairs bigram or trigram or n gram more generally Get a hint of the underlying grammar Normalization from nltk stem snowball import EnglishStemmer stemmer EnglishStemmer input when he flies he likes to fly upon early flights print join stemmer stem x for x in input split when he fli he like to fli upon earli flight Does it matter if you said fly flies or flying Maybe not Stemming is about crude language dependant heuristics chopping the ends off of words Lemmatization

    Original URL path: http://www.njl.us/talks/enough_machine_learning/ (2016-04-27)
    Open archived version from archive



  •