Skip to content

Instantly share code, notes, and snippets.

View ourway's full-sized avatar
🏆

Farshid Ashouri ourway

🏆
View GitHub Profile
@ourway
ourway / gist:8a62f3ce0eeff8808ea75c3b693b491e
Created October 5, 2017 22:02 — forked from fdelbos/gist:1836947
FreeBSD startup script for uWsgi
#!/bin/sh
#
# PROVIDE: myuwsgi
#
. /etc/rc.subr
name=myuwsgi
rcvar=myuwsgi_enable
start_cmd="myuwsgi_start"
@ourway
ourway / distance.sql
Created October 4, 2017 09:35 — forked from mohsenk/distance.sql
MySQL calculate distance between two latitude/longitude coordinates
CREATE FUNCTION `lat_lng_distance` (lat1 FLOAT, lng1 FLOAT, lat2 FLOAT, lng2 FLOAT)
RETURNS FLOAT
DETERMINISTIC
BEGIN
RETURN 6371 * 2 * ASIN(SQRT(
POWER(SIN((lat1 - abs(lat2)) * pi()/180 / 2),
2) + COS(lat1 * pi()/180 ) * COS(abs(lat2) *
pi()/180) * POWER(SIN((lng1 - lng2) *
pi()/180 / 2), 2) ));
END
@ourway
ourway / postgres
Created April 13, 2017 23:45 — forked from mmrwoods/postgres
Postgres maintenance crontab file
# dump all databases once every 24 hours
45 4 * * * root nice -n 19 su - postgres -c "pg_dumpall --clean" | gzip -9 > /var/local/backup/postgres/postgres_all.sql.gz
# vacuum all databases every night (full vacuum on Sunday night, lazy vacuum every other night)
45 3 * * 0 root nice -n 19 su - postgres -c "vacuumdb --all --full --analyze"
45 3 * * 1-6 root nice -n 19 su - postgres -c "vacuumdb --all --analyze --quiet"
# re-index all databases once a week
0 3 * * 0 root nice -n 19 su - postgres -c 'psql -t -c "select datname from pg_database order by datname;" | xargs -n 1 -I"{}" -- psql -U postgres {} -c "reindex database {};"'
@ourway
ourway / periodic_task.ex
Created February 13, 2017 13:29 — forked from trestrantham/periodic_task.ex
Run a task periodically natively in Elixir
defmodule MyApp.Periodically do
use GenServer
def start_link do
GenServer.start_link(__MODULE__, %{})
end
def init(state) do
Process.send_after(self(), :work, 2 * 60 * 60 * 1000) # In 2 hours
{:ok, state}
@ourway
ourway / img_extractor.py
Created July 12, 2016 05:01 — forked from booknara/img_extractor.py
This script help you extract image files from an APK file. Basic Usage (1) img_extractor.py --ifile <APK file> --ofile <Destination Directory> (2) img_extractor.py --ifile <APK file> --ofile . (3) img_extractor.py --ifile <APK file> --ofile ..
#!/usr/bin/python
# This script help you extract image files from an APK file.
# Author : Daehee Han (https://github.com/booknara, @daniel_booknara)
# Date : August 21 2013
# Basic Usage
# (1) img_extractor.py --ifile <APK file> --ofile <Destination Directory>
# (2) img_extractor.py --ifile <APK file> --ofile .
# (3) img_extractor.py --ifile <APK file> --ofile ..
@ourway
ourway / gist:292bf5889580b49ba1b6e18ca533ca8c
Created June 27, 2016 13:17 — forked from z4y4ts/gist:3302920
SQL complex query with aggregation in web2py DAL way

Raw SQL

query = '''SELECT COALESCE(SUM(imp), 0) AS imps,
                  COALESCE(SUM(click), 0) AS clicks
           FROM logCuDate
           WHERE id=%s
               AND date >= %s
               AND date <= %s'''
res = db.executesql(query, args, as_dict=True)
@ourway
ourway / gist:50f1529caaec405e776b74eeb0b0f9c9
Created April 12, 2016 16:20 — forked from sinkers/gist:5cc2854e01a05a2db650
Creating multiple DASH renditions with a bitrate text overlay, using ffmpeg and Bento
#!/bin/sh
# encode_bitrate_overlay.sh
#
#
# Created by Andrew Sinclair on 11/07/2014.
#
#!/bin/bash
VIDSOURCE=$1
OUTNAME=$2
@ourway
ourway / gist:3d31a7383893443cf89044f01f7c534f
Created April 12, 2016 16:19 — forked from sinkers/gist:4e35c1b9922b8bd85452
Encoding HLS and DASH in a simple script, lot's of tweaks to go
#!/usr/bin/python
# Script to encode HLS and DASH from a multi TS mezzanine file
# Places encoded files in a folder of the same name as the source input
# Steps
# 1. Check file with mediainfo (optional)
# 2. Encode to resolutions as mp4
# 3. Split into TS segments and create playlists
# 4. Create variant playlist
import subprocess
from sqlalchemy import create_engine
engine = create_engine('sqlite:///:memory:', echo=True)
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
from sqlalchemy import Column, Integer, String, Float
class User(Base):
__tablename__ = 'users'