Skip to content

Instantly share code, notes, and snippets.

View rightfold's full-sized avatar
🎯
Finally focussing

rightfold rightfold

🎯
Finally focussing
  • Utrecht, Netherlands
View GitHub Profile
do
balanceA <- newTVarIO (400 :: Int)
balanceB <- newTVarIO (900 :: Int)
replicateM_ 100 . forkIO $ do
atomically $ do
modifyTVar balanceA (\x -> x + 2)
modifyTVar balanceB (\x -> x - 2)
readTVarIO balanceA >>= print
readTVarIO balanceB >>= print
@rightfold
rightfold / gist:2011e40f6e9fb3ff8fb5
Created June 18, 2015 07:30
Publish–subscribe in Go
package main
import (
"fmt"
"sync"
"time"
)
type Publisher struct {
mutex sync.RWMutex
function signin_required($login_page, $fn) {
return function($db) use ($fn, $login_page) {
if (array_key_exists('user_id', $_SESSION))
$fn($db);
else engine\redirect($login_page);
};
}
@rightfold
rightfold / gist:39ab58cbf6995fd69817
Last active August 29, 2015 14:22
Thread-unsafety in Rust
use std::sync::{Arc, Mutex};
use std::thread;
fn main() {
let p = Arc::new(Mutex::new(0));
for _ in 1..100 {
let x = p.clone();
thread::spawn(move || {
let n;
identification division.
program-id. hangman.
data division.
working-storage section.
01 state.
05 word pic A(100).
05 word-length pic 9(3).
05 guess pic A.
05 guesses occurs 256 times pic 9.
class Builder{
String message = "";
Builder greet(string only_one){
message += "Hello "
message += only_one;
}
Builder greet(string first, string... rest){
greet(first);
import java.io.InputStream
import java.util.Locale
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.apache.commons.io.IOUtils
import scala.collection.JavaConverters._
case class ConnectionInfo(localAddress: String,
localHost: String,
localPort: Int,
remoteAddress: String,
def abs(x: Number)(ensure out >= 0): Real =
x
|> non-zero-parts()
|> map(fn(x) => x ^ 2)
|> sum()
|> sqrt()
specialize def abs(x: Real): Real =
if x < 0 { -x } else { x }
def abs(x: Number)(ensure out >= 0): Real =
x
|> non-zero-parts()
|> map(fn(x) => x ^ 2)
|> sum()
|> sqrt()
specialize def abs(x: Real): Real =
if x < 0 { -x } else { x }
def abs(x: Number)(ensure out >= 0): Real =
x
|> non-zero-parts()
|> map(fn(x) => x ^ 2)
|> sum()
|> sqrt()
specialize def abs(x: Real): Real =
if x < 0 { -x } else { x }