- 1
- 2
- 3
- 4
Process process = Runtime.getRuntime().exec("su");
OutputStream outputStream = process.getOutputStream();
String cmd = "keycode " + KeyEvent.KEYCODE_BACK;
outputStream.write((cmd + "\n").getBytes("ASCII"));
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+75
Process process = Runtime.getRuntime().exec("su");
OutputStream outputStream = process.getOutputStream();
String cmd = "keycode " + KeyEvent.KEYCODE_BACK;
outputStream.write((cmd + "\n").getBytes("ASCII"));
Андроид. Вот такой вот прекрасный способ программно нажать кнопочку "Back".
http://stackoverflow.com/questions/5832861/android-back-key-by-software
−166
class User < ActiveRecord::Base
def full_name
user_info=User.find(self.id)
[user_info.name,user_info.surname].join(" ")
end
end
Получаем полное имя себя
+49
wordpress:
function __( $text, $domain = 'default' ) {
return translate( $text, $domain );
}
function translate( $text, $domain = 'default' ) {
$translations = &get_translations_for_domain( $domain );
return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain );
}
PHP-manual:
PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality.
wordpress:
/*
* Don't use translate() directly, use __()
*/
+52
<?php
function zvlad_gen($min, $max, $anz) {
$array = range($min, $max);
for($x=0; $x<$anz; $x++) {
$i = rand(1, count($array))-1;
$erg[] = $array[$i];
//array_splice($array, $i, 1);
}
return $erg;
}
// Получить 6 случайных чисел в диапазоне от 121 до 155
$rand_array = zvlad_gen(121, 155, 6);
echo join(", ", $rand_array);
?>
Небольшая функция, которая поможет вывести диапазон чисел. Так же можно вывести несколько вариантов сразу, т.е. что бы не запускать скрипт несколько раз.
Данная функция подойдет сайтам, которые разыгрывают призы, например) Ну, или лотерея какая нибудь.
+117
main = print x where x = x + 0
http://ideone.com/9caQE
result: Runtime error time: 0.01s memory: 3536 kB signal: -1
input: no
output: no
stderr:
prog: <<loop>>
+62
$user = User::model()->findByAttributes(array("email" => $this->username, "is_deleted"=>0));
if (!$user)
{
$user = User::model()->findByAttributes(array("email" => $this->username, "is_deleted"=>0));
}
Видимо так, на всякий случай, ещё раз попробовать решил.
+31
#include <iostream>
#include <tr1/functional>
using namespace std::tr1::placeholders;
struct I
{
int i;
};
struct S
{
int i;
I ii;
};
int main()
{
std::tr1::function<I& (S&)> pi = std::tr1::bind(&S::ii, _1);
std::tr1::function<std::tr1::reference_wrapper<I> (S&)> pri = std::tr1::bind(static_cast<std::tr1::reference_wrapper<I> (*)(I&)>(&std::tr1::ref<I>), std::tr1::bind(pi, _1));
std::tr1::function<int& (S&)> psi = std::tr1::bind(&I::i, std::tr1::bind(&std::tr1::reference_wrapper<I>::get, std::tr1::bind(pri, _1)));
S s = {1, {2}};
std::cout << psi(s) << std::endl;
psi(s) = 3;
std::cout << psi(s) << std::endl;
return 0;
}
Нашёл на RSDN, в теме о том, как получить указатель на член члена.
+75
@Override
public boolean onTouchEvent(MotionEvent e) {
x=(int)e.getX(); y=(int)e.getY();
/* ... */
synchronized(this) {
try {this.wait(1000);}
catch (InterruptedException ex) {}
}
return true;
}
/* Gets (screen/pixel) x,y coordinates of last touch event*/
public boolean GetCoordinates(MutablePoint coordinates) {
if (x==-1) return false;
coordinates.init(x,y);
return true;
}
https://github.com/acl33/AndroidDasher/blob/master/src/dasher/android/DasherCanvas.java
+60
list($width, $height, $type, $attr) = getimagesize($file1);
if($width == $height)
{
set_time_limit(270);
if(filesize($file1) > 102400) return array(false, "Размер больше 100Кб!");
if($type == 1) {$file2 = $file1.'.gif'; $out = $tizer_id.'.gif'; $type = 'gif'; $ext = 'gif';}
elseif($type == 2) {$file2 = $file1.'.jpg'; $out = $tizer_id.'.jpg'; $type = 'jpg'; $ext = 'jpg';}
elseif($type == 3) {$file2 = $file1.'.png'; $out = $tizer_id.'.png'; $type = 'png'; $ext = 'png';}
else return array(false, "Это не картинка!");
/* ... */
}
// no square
else
{
return array(array('img',false, "Изображение не квадратное!"));
}
Зачем жить, если no square
+52
<?
....
//башкортостан
$city_select_arr = "<OPTGROUP LABEL=\"Республика Башкортостан\">";
foreach($city_select_data as $k=>$v) {
{
$global_city = ($_GET['city'] == '' ? $_POST['city_select']: $_GET['city']);
$city_select_arr .= "<option value=\"".$v."".( $v == $global_city ? " selected" : "" ) . "\">".$v."</option>";
}
}
$city_select_arr .= "</OPTGROUP>";
//пермский край
$city_select_arr .= "<OPTGROUP LABEL=\"Пермский край\">";
foreach($city_select2_data as $k=>$v) {
{
$global_city = ($_GET['city'] == '' ? $_POST['city_select']: $_GET['city']);
$city_select_arr .= "<option value=\"".$v."".( $v == $global_city ? "" : "" ) . "\">".$v."</option>";
}
}
$city_select_arr .= "</OPTGROUP>";
.... и так еще циклов 10-15
обратите внимание на переменную $global_city - ей в каждой итерации каждого цикла присваивают условное значение, которое в пределах этого файла точно не меняется :)
ну и сам набор циклов можно было бы конечно систематизировать.