Skip to content

Instantly share code, notes, and snippets.

View odwrotnie's full-sized avatar

Pawel odwrotnie

  • Poland
  • 11:58 (UTC +02:00)
View GitHub Profile
@odwrotnie
odwrotnie / setup-runner-on-linux.sh
Created November 15, 2023 11:51
Setup GitHub Runner on Linux
#!/bin/bash
read -p "Enter server name: " SERVER_NAME
echo "INSTAP_SERVER=${SERVER_NAME}" > env
echo "File 'env' has been created with the server name."
sudo apt -y install jq
mkdir .instap
cd .instap
import annotation.tailrec
import collection.parallel.mutable.ParSeq
def factorize(n: Long): List[Long] = {
@tailrec
def factors(tuple: (Long, Long, List[Long], Int)): List[Long] = {
tuple match {
case (1, _, acc, _) => acc
case (n, k, acc, _) if (n % k == 0) => factors((n / k, k, acc ++ ParSeq(k), Math.sqrt(n / k).toInt))
case (n, k, acc, sqr) if (k < sqr) => factors(n, k + 1, acc, sqr)
val primes = {
def sieve(nums: Stream[Int]): Stream[Int] =
Stream.cons(nums.head, sieve((nums.tail) filter (_ % nums.head != 0)))
sieve(Stream.from(2, 1))
}
println(primes.take(1000).mkString(", "))
# ID Sequences
You can provide a `Sequence` for your `Entities` in order to alter generated ID's from default UUID's.
The traits you can use:
```
trait Entity extends BaseEntity with UUID
trait EntityWithCustomID[ID] extends BaseEntity with CustomID[ID]
trait EntityWithGeneratedID[ID] extends BaseEntity with GeneratedID[ID]
@odwrotnie
odwrotnie / gist:4061429
Created November 12, 2012 19:38
Django save image from URL
class Picture(models.Model):
image = models.ImageField(upload_to = 'realestate/', null = True, blank = True)
...
picture = Picture.objects.create(image = File(open(urllib.urlretrieve(path)[0])))
class DictoList:
def __init__(self):
self.d = {}
def add_keys(self, *keys):
d = self.d
for k in keys:
if not k in d:
d[k] = {}
d = d[k]
def get(self, *keys):
@odwrotnie
odwrotnie / lift-comet.md
Created June 26, 2012 16:05
Lift - comet update

Head

<head>
    <!--<script id="jquery" src="/classpath/jquery.js" type="text/javascript"></script>-->
    <script id="jquery" src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
</head>

Template

import sbt._
import Keys._
import sbtassembly.Plugin._
import AssemblyKeys._
object SWTApp extends Build {
val osName = System.getProperty("os.name")
println("OS name: %s" format osName)
val osArch = System.getProperty("os.arch")
import javax.persistence._
object JPA {
val unit = "jpa"
val emf = Persistence.createEntityManagerFactory(unit)
def t[R](f: EntityManager => R) = {
val em = emf.createEntityManager
val transaction = em.getTransaction
object NotNull {
def apply[R](n: => R)(f: => R) = try {
if (n == null) throw new NullPointerException
n
} catch { case npe: NullPointerException => f }
}