This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
type Publisher struct { | |
mutex sync.RWMutex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Builder{ | |
String message = ""; | |
Builder greet(string only_one){ | |
message += "Hello " | |
message += only_one; | |
} | |
Builder greet(string first, string... rest){ | |
greet(first); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |