Skip to content

Instantly share code, notes, and snippets.

View rssh's full-sized avatar

Ruslan Shevchenko rssh

View GitHub Profile
@rssh
rssh / CommandRunner.scala
Created March 12, 2012 21:00
run command line program within play 2.0 environment
package commands
import scala.sys._
import play.api._
import java.io.File
/**
* Run command in play environment.
*
* Assume, that we have in play 'app' directory subdirectory 'commands'
@rssh
rssh / gist:2506418
Created April 27, 2012 06:19
example of werid print behaviour for Peter
#include <stdio.h>
int main(int argc, char** argv)
{
printf("sizeof(int)=%d, sizeof(long)=%d, sizeof(long long)=%d\n", sizeof(int), sizeof(long), sizeof(long long));
long long check[3];
check[0]=1;
printf("x1=%d, x2=%d, x3=%d\n", check[0],check[0],check[0]);
return 0;
}
@rssh
rssh / gist:3065416
Created July 7, 2012 08:20
dou - Иллюстрация к колонке от 2012-07-07 №1
File in = null;
File out = null;
try {
in = System.out(“input”,read);
try {
out = System.out(“out”, write);
copy(in,out)
} finally {
out.close();
}
@rssh
rssh / gist:3065422
Created July 7, 2012 08:22
dou - Иллюстрация к колонке от 2012-07-07 №2
try {
in = System.openForRead(“name”);
out = System.openForWriting(“output”);
return copy(in,out);
} finally {
if (in!=null) {
try {
in.close();
} finally {
if (out!=null) {
@rssh
rssh / gist:3065424
Created July 7, 2012 08:23
dou - Иллюстрация к колонке от 2012-07-07 №3
{
auto in = File(“input”,"r");
scope(exit){ in.close(); }
auto out = File(“output”,"w");
scope(exit){ out.close(); }
out.copyFrom(in);
}
@rssh
rssh / gist:3065558
Created July 7, 2012 09:01
dou - Иллюстрация к колонке от 2012-07-07 №4
func CopyFile(dstName, srcName string) (written int64, err error) {
src, err := os.Open(srcName)
if err != nil {
return
}
defer src.Close()
dst, err := os.Create(dstName)
if err != nil {
return
@rssh
rssh / gist:3065561
Created July 7, 2012 09:04
dou - Иллюстрация к колонке от 2012-07-07 №5
function(students) {
var retval = [ ];
for(var s in students) {
if (students.hasOwnProperty(s)) {
if (s.course == 4) {
retval.add(s.name)
}
}
}
return retval;
@rssh
rssh / gist:3065562
Created July 7, 2012 09:04
dou - Иллюстрация к колонке от 2012-07-07 №5
function(students) {
var retval = [ ];
for(var s in students) {
if (students.hasOwnProperty(s)) {
if (students[s].course == 4) {
retval.add(students[s].name)
}
}
}
return retval;
@rssh
rssh / JobActionSimplicited.scala
Created July 18, 2012 06:42
jobAction simplicified (yet not ideal)
object JobAction {
def apply(f: JobRequest => Result) = process(mustBeAuthenticated=false)(f)
def authenticated = process(mustBeAuthenticated=true) _
def owner(id: ObjectId) = process(mustBeAuthenticated=true, optUserId = Option(id)) _
def admin = process(mustBeAuthenticated=true, mustBeAdmin=true) _
@rssh
rssh / JobActionSimplicitedEx.scala
Created July 18, 2012 06:45
GobAction simplicified with commented out variants.
package controllers
import models.Account
import play.api.mvc._
import org.bson.types.ObjectId
import play.api.mvc.Results._
import play.api.i18n.Messages
object JobAction {