Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'sinatra'
get '/hi' do
"hello world!!"
end
@dwiash
dwiash / Upload.php
Created September 30, 2009 06:14
Simple file uploader (PHP)
<?php
if($_POST['submit'] == "submit"){
$uploaddir = $_POST['dir'];
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo "<span style='color:#00f' >File was successfully uploaded.</span><hr />";
}
else
{
echo "<span style='color:#f00' >Upload failed!</span><hr />";
@dwiash
dwiash / exec.php
Created September 30, 2009 09:50
execute system command from web interface
<?php
if($_POST['exec'] == 'exec'){
$r = system($_POST['command'], $l);
// debug
print($r);
print('<hr/>');
print($l);
print('<hr/>');
}
@dwiash
dwiash / write.php
Created October 4, 2009 14:56
nulis ke file pake PHP
<?php
// kasih nama file yg jadi sasaran buat nulisnya
$nama_file = 'test.txt';
// ini text yang mau dimasukin ke dalem filenya
$text_yang_mau_dimasukin = "ini textnya, ini textnya, ini textnya, ini textnya, ini textnya, ";
// pertama buka filenya dulu, kalo filenya ngga ada, bakal dibikin secara otomatis
sudo add-apt-repository ppa:nvidia-vdpau/ppa
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function init():void
{
tx.text = "Hey!";
}
@dwiash
dwiash / process.php
Created December 12, 2009 12:30
upload+proses file CSV
<?php
$temp_file = $_FILES["berkas"]["tmp_name"];
if($_FILES["berkas"]["error"] == 0){
$handle = @fopen($temp_file, "r");
if ($handle) {
$arr = array(); // ini variable Array yang dipake buat nyimpen data dari CSV yang diupload
while (!feof($handle)) {
$buffer = fgets($handle);
@dwiash
dwiash / Main.java
Created January 21, 2010 10:19
jawaban dari salah satu soal pada CSPC
/*
[jawaban dari salah satu soal pada CSPC]
program ini menghitung setiap kemungkinan ketika sejumlah uang ditukarkan dengan pecahan 50ribu, 20ribu, 10ribu atau seribu.
Misalnya untuk nilai 15000, akan menghasilkan kemungkinan:
1 10ribuan, 5 seribuan
15 seribuan
cara menjalankan program ini:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try {
File fileInput = new File("input.txt");
BufferedReader buffRead = null;
#!/bin/sh
cp_p()
{
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d%% [", percent
for (i=0;i<=percent;i++)