Skip to content

Instantly share code, notes, and snippets.

View solidfox's full-sized avatar

Daniel Schlaug solidfox

View GitHub Profile
@solidfox
solidfox / react-gotcha-closure-component.jsx
Created March 17, 2018 12:54
Component with closure of state and dispatch will make React replace everyting inside AppBody on every re-render.
function AppComponent({state, dispatch}) {
// Component with closure of state and dispatch will make React replace everyting
// inside AppBody on every re-render.
function AppBody() {
switch (state.get('page')) {
case "dish-details":
return <DishDetails key='dishDetails'
dish={core.getBestInformationOnSelectedDish(state)}
nGuests={state.get("nGuests")}
dispatch={dispatch}/>

Keybase proof

I hereby claim:

  • I am solidfox on github.
  • I am solidfox (https://keybase.io/solidfox) on keybase.
  • I have a public key ASAVwafynYFK2UqZwJ4CmfJb68GaTKPBrD5sk_8XZkflZAo

To claim this, I am signing this object:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /opt/homebrew-cask/Caskroom/pycharm/4.0.3/PyCharm.app/Contents/helpers/pycharm/utrunner.py "/Users/spike/Git Clones/dd2434project/kernels/test_ngkernel_IT.py::TestNgkernelIT::test_ngkernel_gram_matrix" true
Testing started at 18:43 ...
Warning: Empty element: '<REUTERS TOPICS="NO" LEWISSPLIT="TRAIN" CGISPLIT="TRAINING-SET" OLDID="1762" NEWID="12793">\n<DATE> 3-APR-1987 07:09:06.48</DATE>\n<TOPICS/>\n<PLACES/>\n<PEOPLE/>\n<ORGS/>\n<EXCHANGES/>\n<COMPANIES/>\n<TEXT TYPE="UNPROC">\n\n\n</TEXT>\n</REUTERS>\n'
---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------- ---------- ---------- ---------- ---------- -------- --------- ---------- ---------- --------- ---------- ---------- ---------- ---------- --------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------- ---------- -------- -------- ----------
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 "/Users/spike/Git Clones/dd2434project/findadvantage.py"
Warning: Empty element: '<REUTERS TOPICS="NO" LEWISSPLIT="TRAIN" CGISPLIT="TRAINING-SET" OLDID="1762" NEWID="12793">\n<DATE> 3-APR-1987 07:09:06.48</DATE>\n<TOPICS/>\n<PLACES/>\n<PEOPLE/>\n<ORGS/>\n<EXCHANGES/>\n<COMPANIES/>\n<TEXT TYPE="UNPROC">\n\n\n</TEXT>\n</REUTERS>\n'
Length: 5.000000, weight decay: 0.010000
Advantage: 0.328698, indices: (378, 51)
()
['earn']: service corp international srv rd qtr net qtr ended jan shr cts vs cts net mln vs mln revs mln vs mln avg shrs mln vs mln nine mths shr cts vs cts net mln vs mln revs mln vs mln avg shrs mln vs mln note net nine mths includes gains dispositions dlrs four cts share vs dlrs two cts share avg shrs shr data restated reflect threefortwo stock split january reuter
()
['earn']: bowater pretax profits rise mln stg shr p vs p div p vs p making p vs p turnover billion stg vs billion pretax profit mln vs mln tax mln vs mln company
expected_result_for_length = [
(1, 0.849),
(2, 0.580),
(3, 0.478),
(4, 0.439),
(5, 0.406),
(6, 0.370),
]
str1 = "science is organized knowledge"
@solidfox
solidfox / gist:fe4b277302b56a552af1
Created January 3, 2015 12:14
Longest body of the used articles in the Reuters ModApte-split stopwords and punctuation removed
us supplydemand detailed usda us agriculture department made following supplydemand projections 198687 seasons mln bushels comparisons unless noted corn 198687 198586 040987 030987 040987 030987 acreage mln acres planted 767 767 834 834 harvested 692 692 752 752 yield bu 1193 1193 1180 1180 supply mln bu start stock 4040 4040 1648 1648 production 8253 8253 8877 8877 totalx 12295 12295 10536 10536 xincludes imports corn cont 198687 198586 040987 030987 040987 030987 usage feed 4500 4300 4095 4126 1180 1150 1160 1129 ttl domest 5680 5450 5255 5255 exports 1375 1250 1241 1241 total use 7055 6700 6496 6496 end stocks 5240 5595 4040 4040 farmer reser 1400 1300 564 564 ccc stocks 1700 1500 546 546 free stocks 2140 2795 2930 2930 avgprice 135165 135165 223 223 note price dlrs per bu corn season begins sept 1 wheat 198687 198586 040987 030987 040987 030987 acreage mln acres planted 720 720 756 756 harvested 607 607 647 647 yield 344 344 375 375 supply mln bu start stcks 1905 1905 1425 1425 production 2087 2087 2425 2
@solidfox
solidfox / Fix crappy course lists.js
Last active December 17, 2015 23:38
The KTH Computer Science Master program page (http://www.kth.se/student/kurser/program/TCSCM/HT10/kurslista) should be considered broken in it's current state. This code will fix it.
// For use on sites with crappy KTH course lists like
// http://www.kth.se/student/kurser/program/TCSCM/HT10/kurslista
// By Daniel Schlaug May 2013
var body = document.getElementsByTagName("body")[0];
function buildCourseLink(courseCode) {
// Clumsy way of finding the course title but it works
$.get("/student/kurser/kurs/" + courseCode, function (coursePage) {
var title = $(coursePage).filter('title').text().replace(/^KTH \| /, "");
$('.' + courseCode).text(title);