Skip to content

Instantly share code, notes, and snippets.

View goFrendiAsgard's full-sized avatar

Go Frendi Gunawan goFrendiAsgard

View GitHub Profile
@goFrendiAsgard
goFrendiAsgard / register.php
Created October 2, 2012 04:02
No-CMS upload file technique to avoid duplicate file name
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// you can also extends CI_Controller for normal CodeIgniter code
class Register extends CMS_Controller{
// this is the upload path
$upload_path = BASEPATH.'../modules/ssc/assets/upload/';
// this is how to use it
public function upload(){
$file = $_FILES['user_file'];
@goFrendiAsgard
goFrendiAsgard / Setup_Aptana.txt
Created October 20, 2012 05:59
Using Aptana as killer web-app (and python) IDE
Aptana is a killer editor, the one IDE to rule everything in web realms. It support PHP, Python, Rubby, Python, Javascript, CSS and HTML. It's free, so you can just use it and start to do wonderful things.
Base installation :
1. Install Eclipse
2. Run eclipse
3. Go to: Help > Install New Software
4. Press Add button
5. Add Location "http://download.aptana.com/studio3/plugin/install", name it as "Aptana Plugin" or whatever
6. Back to Help > Install New Software (or just close the previous dialog)
7. Choose "Aptana Plugin" in Work With input
@goFrendiAsgard
goFrendiAsgard / sql_alchemy_non_orm.py
Created April 7, 2013 06:52
Using SQL Alchemy to run a plain SQL syntax
# create engine
from kokoropy.sqlalchemy import create_engine
engine = create_engine('sqlite:///non_orm.db', echo=True)
# create metadata of table schemas
from kokoropy.sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey
metadata = MetaData()
users = Table('users', metadata,
Column('user_id', Integer, primary_key=True),
Column('user_name', String),
@goFrendiAsgard
goFrendiAsgard / .htaccess
Created May 20, 2013 05:58
htaccess of /forum/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forum/index.php [L]
</IfModule>
@goFrendiAsgard
goFrendiAsgard / example.py
Last active December 17, 2015 16:49
Decoding json into SQL in python. Asked by https://www.facebook.com/wintang.murtiari
import json
# this is your json
my_json_data = '{"nick_name" : "Annakin", "family_name" : "Skywalker"}'
# this is the decoded json
my_data = json.loads(my_json_data)
# sql command
sql = "INSERT INTO tbl(nick_name, family_name) VALUES('"+my_data["nick_name"]+"', '"+my_data["family_name"]+"')"
@goFrendiAsgard
goFrendiAsgard / try.py
Created March 20, 2014 17:51
SQLAlchemy and alembic
from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
############################### SQL ALCHEMY SCRIPT ####################################
# create Base
Base = declarative_base()
# create Pokemon class
@goFrendiAsgard
goFrendiAsgard / extend_base.py
Created April 10, 2014 23:04
Extend SQL Alchemy's Base to avoid multiple inherritance
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy import Column, Integer, String
Base = declarative_base()
class CustomBase(Base):
__abstract__ = True
def __init__(self):
print "Hello world"
@goFrendiAsgard
goFrendiAsgard / Scaffold application in kokoropy
Created April 29, 2014 04:51
Scaffold application in kokoropy (just in case I run out idea about what complex situation I need to write)
python rossian.py scaffold-crud coba orang nama:String-50 alamat:String-50 ayah:orang:manytoone ibu:orang:manytoone teman:orang:onetomany anak:orang:onetomany jurus:jurus:onetomany pekerjaan:pekerjaan:manytoone hobi:hobi:manytomany tanggal_lahir:Date
@goFrendiAsgard
goFrendiAsgard / concurrency.go
Last active August 29, 2015 14:00
Try concurrency
package main
import (
"fmt"
"time"
)
func write(n int){
for i := 0; i<100; i++ {
@goFrendiAsgard
goFrendiAsgard / prof_04_01.java
Last active August 29, 2015 14:00
Superb-Linked-List (in java). I don't like to code in java. However sometime I have to. This is an example of how to make a superb-linked-list in java. The linked-list has both queue & stack mechanism, plus it support to push data on the correct order.
package prof_04_01;
class Node{
int data;
Node next;
Node prev;
public Node(int new_data){
data = new_data;
}
}