Skip to content

Instantly share code, notes, and snippets.

@plentz
plentz / nginx.conf
Last active May 27, 2025 10:32
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@adrianholovaty
adrianholovaty / stuff.py
Created September 5, 2013 04:31
Django two-phased template rendering
# Two-phased template rendering.
# See http://www.holovaty.com/writing/django-two-phased-rendering/
# LICENSE: Public domain.
################
# TEMPLATE TAG #
################
from django import template
register = template.Library()
@cvan
cvan / gist:6444031
Created September 4, 2013 23:07
convert URI of image to data URI
// Load an image in your browser and paste this in your console
var i=new Image();i.src=document.location.href;i.onload=function(){var c=document.createElement('canvas');c.width=this.width;c.height=this.height;c.getContext('2d').drawImage(this,0,0);window.location=c.toDataURL('image/png');};
class EverythingCollector(Collector):
"""
More or less identical to the default Django collector except we always
return relations (even when they shouldnt matter).
"""
def collect(self, objs, source=None, nullable=False, collect_related=True,
source_attr=None, reverse_dependency=False):
new_objs = self.add(objs)
if not new_objs:
return
@adammeghji
adammeghji / gist:5637522
Created May 23, 2013 16:48
Convert a PostgreSQL database from SQL_ASCII to UTF8 encoding
# convert createdb's template to UTF8
echo "UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';" | psql -U postgres
echo "drop database template1;" | psql -U postgres
echo "create database template1 with template = template0 encoding = 'UTF8';" | psql -U postgres
echo "update pg_database set datacl='{=c/postgres,postgres=CTc/postgres}' where datname='template1';" | psql -U postgres
echo "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';" | psql -U postgres
# export and reimport as UTF8
pg_dump -U uniiverse --encoding utf8 mydatabase -f mydatabase_utf8.sql
createdb -U postgres -E utf8 mydatabase_utf8
@sadache
sadache / gist:4714280
Last active July 14, 2022 15:09
Playframework: Async, Reactive, Threads, Futures, ExecutionContexts

Asynchronicity is the price to pay, you better know what you're paying for...

Let's share some vocabulary first:

Thread: The primitive responsible of executing code on the processor, you can give an existing (or a new) Thread some code, and it will execute it. Normally you can have a few hundreds on a JVM, arguments that you can tweak your way out to thousands. Worth noting that multitasking is achieved when using multiple Threads. Multiple Threads can exist for a single processor in which case multitasking happens when this processor switches between threads, called context switching, which will give the impression of things happenning in parallel. An example of a direct, and probably naive, use of a new Thread in Java:

public class MyRunnable implements Runnable {
  public void run(){
 System.out.println("MyRunnable running");
@kylefox
kylefox / gist:4512777
Created January 11, 2013 18:15
If you want to use Xcode's FileMerge as your git mergetool, this is how you set it up.
# Tell system when Xcode utilities live:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
# Set "opendiff" as the default mergetool globally:
git config --global merge.tool opendiff
@oleiade
oleiade / spark-thoughts.md
Created December 7, 2012 11:32
Spark thoughts

Spark

Rdd

  • Spark manipulates input datas as RDD, which basically are distributed datasets.
  • RDD transformations (map) are lazy. It's like a roadmap of transformations to operate over dataset. But lazy, still.
  • RDD actions evaluates transformations and reduces in order to generate and return the result.
  • RDD transformations are re-evaluated on each actions by default unless you cache them

tips

@bmjsmith
bmjsmith / Admin.scala
Created July 22, 2012 20:07
Securing play 2.0 controllers sans boilerplate.
object Admin extends SecureableController {
implicit val requiredRight: Option[Right] = Some(Right("admin"))
def categories = authorized[AnyContent] { implicit request =>
Ok(html.adminCategories(Messages("admin.categories.title")))
}
}
@brikis98
brikis98 / crawler.scala
Created April 1, 2012 20:05
Seven Languages in Seven Weeks: Scala, Day 3
import io.Source
import scala.actors.Actor._
// Regex to pick up external links; very simplified, so it'll miss some
val linkRegex = "(?i)<a.+?href=\"(http.+?)\".*?>(.+?)</a>".r
object PageLoader {
def load(url: String) = {
try {
Source.fromURL(url).mkString