Skip to content

Instantly share code, notes, and snippets.

View omidraha's full-sized avatar
🦋
♥‿♥

Omid Raha omidraha

🦋
♥‿♥
View GitHub Profile
from hashlib import sha256
import os
from pyramid.session import SignedCookieSessionFactory
def make_session_id():
rand = os.urandom(16)
return sha256(sha256(rand).digest()).hexdigest()
class MemorySessionSerializer(object):
@mmerickel
mmerickel / gist:8035611
Created December 19, 2013 07:25
backend-based session storage in pyramid
from hashlib import sha256
import os
from pyramid.session import SignedCookieSessionFactory
def make_session_id():
rand = os.urandom()
return sha256(sha256(rand).digest()).hexdigest()
class MemorySessionSerializer(object):
@bclymer
bclymer / HttpClient.kt
Created January 21, 2016 19:00
Kotlin Realm Primitive Arrays Workaround
val realmIntArrayType = object : TypeToken<RealmIntArray>() {}.type
val realmLongArrayType = object : TypeToken<RealmLongArray>() {}.type
val realmStringArrayType = object : TypeToken<RealmStringArray>() {}.type
val gson = GsonBuilder()
.setExclusionStrategies(object : ExclusionStrategy {
override fun shouldSkipClass(clazz: Class<*>?): Boolean {
return false
}
override fun shouldSkipField(f: FieldAttributes?): Boolean {
@aaltat
aaltat / foobar.py
Created January 11, 2017 17:00
Register browser in Selenium2Library
from selenium import webdriver
from robot.libraries.BuiltIn import BuiltIn
def open_my_browser(url):
# Code here to open browser your my way
driver = webdriver.Chrome()
# Code here to open browser my way ends
driver.get(url)
s2l = BuiltIn().get_library_instance('Selenium2Library')
# HAProxy config for hoodie + ssl.
# Uses nginx for file serving on 127.0.0.1:5999
# This is optional, Hoodie can serve static files fine.
global
log 127.0.0.1 local0 debug
maxconn 4096
user haproxy
group haproxy
daemon

CockroachDB + Django ORM

cockroachdb/sqlalchemy-cockroachdb#14

TODO

  1. fork django/contrib/postgres driver
  2. patch blocking postgres compatibility issues
  3. review with cockroachdb team to see if any issues can be fixed by cockroach
  4. review with django team
  5. merge adapter as separate cockroachdb adapter
  6. write docs, any admin work, etc.
@next2you
next2you / Postgres Index Usage.sql
Created October 15, 2010 20:12 — forked from sriedel/Postgres Index Usage
Postgres: Determine table/index size
SELECT idx.relname as table,
idx.indexrelname as index,
pg_relation_size( idx.indexrelname::text )/1024/1024 as bytes,
cls.relpages as pages,
cls.reltuples as tuples,
idx.idx_scan as scanned,
idx.idx_tup_read as read,
idx.idx_tup_fetch as fetched
FROM pg_stat_user_indexes idx,
pg_class cls ,
@petersaints
petersaints / activity_scrolling.xml
Created April 26, 2016 14:36
Android Scrolling Activity Example
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="pt.unl.fct.di.novalincs.yanux.scavenger.ScrollingActivity">
<android.support.design.widget.AppBarLayout
@mgedmin
mgedmin / conf.py.rst
Created July 22, 2013 10:37
HOWTO add "Show on GitHub" and "Edit on GitHub" links to the Sphinx sidebar

Edit on GitHub links for Sphinx

Create _ext/ and _templates/ subdirectories.

Move edit_on_github.py into the _ext/ subdirectory.

Move sourcelink.html into the _templates/ subdirectory.

Add the following after the import sys, os line :

@spiritinlife
spiritinlife / easy_localization_keys_extractor.dart
Last active January 20, 2022 11:09
Extract language keys from your source code and merge them into existing translations.
/// This is inspired by intl_translation extract command https://github.com/dart-lang/intl_translation/blob/8a5e883d7fe07b0244adbaf3489ceb3b08385483/bin/extract_to_arb.dart
/// and is a slimed down rough version of it. Most of the code is from this package which is an excellent learning resource for anyone who wants
/// to play around with the dart analyzer.
/// This is a rough script, to extract localization keys for the easy_localization library. It will analyze the souce
/// code and find occurrences of tr and plural ( you could add other method names e.g. gender etc ) and extract the argument at index $argumentIndex
/// which should be the translation key. It then merges those keys to your current translated keys and spits the merged version where the
/// untranslated keys have a value of "MISSING".
/// Known issues
/// tr( isSomething ? "true_key" : "false_key", context ) -> will get this as key isSomething ? "true_key" : "false_key"