Skip to content

Instantly share code, notes, and snippets.

@phylake
phylake / vigenere.rb
Created February 9, 2012 23:35
1.61803398874.com solution
l = "xfbhlqtlj".split('').collect {|c| c[0] - 97}
k = [6,1,8,0,3,3,9,8,8]
l = l.zip(k).collect do |p|
t = (p[0] - p[1]) % 26
t += 97
t.chr
end
p l.join('')
@phylake
phylake / .gemrc
Created February 29, 2012 20:18
gemrc
gem: --no-rdoc --no-ri
@phylake
phylake / logicalOR_replacement.md
Last active December 16, 2015 04:49
reg ex goodies

Replace all logical or assignment A ||= B with A || (A = B)

([^\s]+) \|\|= (.*);

$1 || ($1 = $2);

@phylake
phylake / Main.as
Last active December 16, 2015 17:29
closure challenge
package
{
import flash.display.Sprite;
import flash.events.Event;
/**
* 1. What will be printed to the console (via the trace statement)?
* 2. What is the value of this inside of nested()
*/
public class Main extends Sprite

Assignment in most other languages could be thought of as a stateful computation. For instance, when we do x = 5 in an imperative language, it will usually assign the value 5 to the variable x and it will also have the value 5 as an expression. If you look at that functionally, you could look at it as a function that takes a state (that is, all the variables that have been assigned previously) and returns a result (in this case 5) and a new state, which would be all the previous variable mappings plus the newly assigned variable.

http://learnyouahaskell.com/for-a-few-monads-more#state

@phylake
phylake / openssl.md
Last active February 4, 2019 20:25
openssl help
#!/bin/bash
# LC_CTYPE is for darwin
cat /dev/urandom | LC_CTYPE=C tr -cd 'a-f0-9' | head -c 32
@phylake
phylake / _service.md
Last active August 29, 2015 13:56 — forked from naholyr/_service.md

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@phylake
phylake / warp.hs
Last active August 29, 2015 14:04
"hello world" warp app
-- warp-2.1.5.2
-- ghc -O2 -threaded -rtsopts warp
-- ./warp +RTS -N -A1G
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Blaze.ByteString.Builder (copyByteString)
import Data.Text (unpack)
import Network.HTTP.Types.Status (status200)
import Network.Wai
@phylake
phylake / main.hs
Created July 21, 2014 23:24
could not deduce b ~ b1
module Main where
class A a where
class B a where
foo :: (A a, B b) => IO a -> (a -> IO b) -> IO ()
foo _ func = return ()
where
-- this breaks because func is not passed in
barBroken :: (A a, B b) => a -> IO b