Skip to content

Instantly share code, notes, and snippets.

View femmerling's full-sized avatar
🛠️
Building things

Fauzan Erich Emmerling femmerling

🛠️
Building things
View GitHub Profile
@femmerling
femmerling / authenticate.py
Last active June 13, 2022 17:18
I have to create user authentication using python-ldap. After googling around and trying out stuffs, this is the final code for you to use. Please remember to adjust the user_dn, and base_dn accordingly to the format used in your LDAP server.
# to be able to import ldap run pip install python-ldap
import ldap
if __name__ == "__main__":
ldap_server="x.x.x.x"
username = "someuser"
password= "somepassword"
# the following is the user_dn format provided by the ldap server
user_dn = "uid="+username+",ou=someou,dc=somedc,dc=local"
@femmerling
femmerling / owncloudUserCreateHack.php
Created April 3, 2013 11:13
Put this file in your OwnCloud root folder to have a create new user API. All you need to do is have a POST request to <host>/owncloud/owncloudUserCreateHack.php with username and password parameters and your user is created. Remember that this works under SQLite3. Adjust to MySQL or PostgreSQL or whatever engine query you're using.
<?php
require_once '3rdparty/phpass/PasswordHash.php';
class MyDB extends SQLite3
{
function __construct()
{
$this->open('data/owncloud.db');
}
@femmerling
femmerling / ftpserver.py
Created June 5, 2013 11:40
Simple python ftp server with authentication
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
authorizer = DummyAuthorizer()
authorizer.add_user("user", "password", "/home/user", perm="elradfmw")
authorizer.add_anonymous("/home/nobody")
handler = FTPHandler
handler.authorizer = authorizer
@femmerling
femmerling / app.py
Created September 9, 2013 13:52
Always error and class instance always created twice
from flask import Flask, jsonify
from oauth1.authorize import Oauth1
from oauth1.errors.oauth import Oauth1Errors
from oauth1.store.sql import Oauth1StoreSQLAlchemy
BASE_URL = "http://localhost:5000/"
auth = None
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://root:somepassword@127.0.0.1:3306/oauth" # Change this to a valid URI
@femmerling
femmerling / parse_helper.py
Created October 11, 2013 12:05
Function to simplify json parsing for SQLAlchemy model creation
"""
I know that parsing json values for SQLAlchemy models is a pain in the ass.
The following two helpers will get you cleaner code and handles the json while converting it into code.
This is commonly use in Flask-SQLAlchemy applications. My latest backyard release already included these functions
"""
import json
# this import is just an example of an SQLAlchemy module, it can be any model that you wish to use
from app.models import User
@femmerling
femmerling / parser.py
Created January 22, 2014 09:15
Have problems checking class variable type to ensure that value will be typecasted accordingly
def parser(passed_object, request_data):
for item in request_data.values:
if hasattr(passed_object, item) and request_data.values.get(item) != None:
inputval = request_data.values.get(item)
#TODO: check the corresponding class variable type before typecasting
setattr(passed_object, item, inputval)
return passed_object
@femmerling
femmerling / build.gradle
Created January 29, 2015 10:29
project root build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// this is the robojava plugin
classpath 'com.kageiit:robojava-plugin:1.+'
// this is for cobertura so you have test coverage check
classpath("net.saliman:gradle-cobertura-plugin:2.2.5") {
@femmerling
femmerling / build.gradle
Created January 29, 2015 10:33
App build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.emfeld.mvptest"
minSdkVersion 15
targetSdkVersion 21
@femmerling
femmerling / build.gradle
Created January 29, 2015 10:37
Test module build.gradle
// fill this with the name of your app in gradle settings
evaluationDependsOn(':app')
ext.androidProject = 'app'
apply plugin: 'cobertura'
apply plugin: 'com.kageiit.robojava'
cobertura {
coverageFormats = ['html', 'xml']
coverageIgnoreTrivial = true
coverageIgnores = ['org.slf4j.Logger.*']
@femmerling
femmerling / config.yml
Created June 18, 2016 12:05
Example Yaml file for MotherNature use
COMMON:
DEBUG: false
TESTING: false
IS_PRODUCTION: False
TEST:
TESTING: true
DEVELOPMENT:
DEBUG: true
TESTING: false
STAGING: