Skip to content

Instantly share code, notes, and snippets.

@gurix
gurix / output.txt
Last active August 29, 2015 14:10
Perceptron Learning with 3 inputs
1 x0: 1 x1: 0 x2: 1 desired: 1 current: 0 w0: -0.4 w1: 0.5 w2: -0.4 sum: -0.8
w0: -0.1 w2: -0.1
2 x0: 0 x1: 1 x2: 1 desired: 1 current: 1 w0: -0.1 w1: 0.5 w2: -0.1 sum: 0.4
3 x0: 1 x1: 1 x2: 1 desired: 1 current: 1 w0: -0.1 w1: 0.5 w2: -0.1 sum: 0.3
4 x0: 0 x1: 0 x2: 1 desired: 0 current: 0 w0: -0.1 w1: 0.5 w2: -0.1 sum: -0.1
5 x0: 1 x1: 0 x2: 1 desired: 1 current: 0 w0: -0.1 w1: 0.5 w2: -0.1 sum: -0.2
w0: 0.2 w2: -0.4
6 x0: 0 x1: 1 x2: 1 desired: 1 current: 1 w0: 0.2 w1: 0.5 w2: -0.4 sum: 0.1
7 x0: 1 x1: 1 x2: 1 desired: 1 current: 1 w0: 0.2 w1: 0.5 w2: -0.4 sum: 0.3
8 x0: 0 x1: 0 x2: 1 desired: 0 current: 0 w0: 0.2 w1: 0.5 w2: -0.4 sum: -0.4
@gurix
gurix / alpha.R
Created November 11, 2015 09:24
Monkey patch alpha function in psych package to suppress the direct output for items were negatively correlated with the total scale
"alpha" <- function(x,keys=NULL,cumulative=FALSE,title=NULL,max=10,na.rm=TRUE,check.keys=FALSE,n.iter=1,delete=TRUE,use="pairwise") { #find coefficient alpha given a data frame or a matrix
alpha.1 <- function(C,R) {
n <- dim(C)[2]
alpha.raw <- (1- tr(C)/sum(C))*(n/(n-1))
alpha.std <- (1- n/sum(R))*(n/(n-1))
smc.R <- smc(R)
G6 <- (1- (n-sum(smc.R))/sum(R))
av.r <- (sum(R)-n)/(n*(n-1))
sn <- n*av.r/(1-av.r)
@gurix
gurix / randomizable.rb
Created November 18, 2015 16:36
Concern to get random document(s) from a model via mongoid, see http://stackoverflow.com/questions/7759250/mongoid-random-document/33784640#33784640
module Randomizable
extend ActiveSupport::Concern
module ClassMethods
def random(n = 1)
indexes = (0..count - 1).sort_by { rand }.slice(0, n).collect!
return skip(indexes.first).first if n == 1
indexes.map { |index| skip(index).first }
end
@gurix
gurix / INSTALL.md
Last active February 2, 2018 13:29
How to install pandoc 1.17.0.3 on ueberspace 6

The following worklow based on the official documentation from pandoc https://pandoc.org/installing.html#quick-stack-method

Install stack

Stack is not installed on ueberspace 6 by default. So we have to do install it manually.

  1. Download the release Linux 64-bit, static mannually according https://docs.haskellstack.org/en/stable/install_and_upgrade/#linux with the command wget https://www.stackage.org/stack/linux-x86_64-static
  2. It is a tar archive, but it does not save it with the correct suffix. However we cann extract the archive using tar -xzf linux-x86_64-static
  3. Copy the stack binary into your home binary folder cp stack-1.6.3-linux-x86_64-static/stack ~/bin/

Install pandoc

  1. Download the pandoc source wget https://hackage.haskell.org/package/pandoc-1.17.0.3/pandoc-1.17.0.3.tar.gz
  2. Extract the archive tar xvzf pandoc-1.17.0.3.tar.gz
@gurix
gurix / cannabis-infused-chai.en.md
Last active May 31, 2018 13:18
Cannabis Infused Masala Chai

Cannabis Infused Masala Chai

milk-tea-masala-chai

Ingredients

  • 0.2 dl Water
  • 0.2 dl Milk (high fat content)
  • 1 Gramm Cannabis
  • 1 Teabag Chai Tea
  • Sugar (as much as you prefere)
@gurix
gurix / easy_gov_review.ssml
Created July 2, 2018 18:51
EasyGov Review
<speak>
<amazon:auto-breaths volume="x-loud" frequency="x-high">The following sequence shows the keyboard only navigation through the homepage of easygov from top to bottom. To do that, i am using the tabulator key. As you can see, the element that has the focus is sometimes highlighted with a light blue border.</amazon:auto-breaths></speak>
@gurix
gurix / hstore_pivot.sql
Created April 9, 2014 10:01
Creating a cross tab / pivot table form hstore fields with dynamical column names using in postgresql
DROP TABLE IF EXISTS survey_sessions;
-- Imagine a table with survey sessions
-- token: some id or token to access a survey
-- answers: a key value store for answers
CREATE TABLE survey_sessions (
token text,
answers hstore);
-- We need some data to play with
INSERT INTO survey_sessions (token, answers) VALUES ('9IaxxP', 'a=>1, b=>2');

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

$("tbody tr").each(function() {$(this).find("input[type=radio]")[Math.floor(Math.random()*4)].click()}); $("input[type=submit]").click();
const images = require.context('../images')
const state = {
images: images.keys().map(function(name) {
return({
name: name,
path: images(name,true)
})
})
}