- 1
- 2
- 3
https://pbs.twimg.com/media/Dl4x_P-XsAAPfgC.jpg
https://twitter.com/_inside/status/1035319938641276928 The Apple Watch pride face is hardcoded to not show up if the paired iPhone is using the Russian locale
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
https://pbs.twimg.com/media/Dl4x_P-XsAAPfgC.jpg
https://twitter.com/_inside/status/1035319938641276928 The Apple Watch pride face is hardcoded to not show up if the paired iPhone is using the Russian locale
> Однако 30 октября 2014 года в статье на Bloomberg Businessweek Кук совершил каминг-аут, признавшись в своей гомосексуальности, и выразил надежду, что это признание поможет другим геям принять себя и вдохновит их на борьбу за свои права.
Бабло победило принципы
+1
-
#
## #### #### ##### ######
# # # # # # # #
# # #### # # #####
# ### # # ##### #
# ### # # # # # # #
##### ### #### #### # # #
# # ###### ##### # ###### # #### ## ##### # #### # #
# # # # # # # # # # # # # # # # ## #
# # ##### # # # ##### # # # # # # # # # # #
# # # ##### # # # # ###### # # # # # # #
# # # # # # # # # # # # # # # # # ##
## ###### # # # # # #### # # # # #### # #
###### ##### ##### #### #####
# # # # # # # # #
##### # # # # # # # #
# ##### ##### # # #####
# # # # # # # # #
###### # # # # #### # #
+1
class TaxStorage {
public:
using TaxCode = Code<3>; // Code<int N, typename Storage = uint32_t> тип для маленьких строк
using TaxType = Code<3>;
using TaxId = std::tuple<TaxCode, TaxType>;
using TaxMap = std::map<TaxId, int>
using CityId = int;
using TaxPointMap = std::unordered_map<CityId, TaxMap>;
TaxMap forCityOrOther(const TaxPointMap& map, const CityId cityId) const {
const auto found = map.find(cityId);
return found == map.cend() ? map.at(OTHER_CITY) : *found; // должно быть found->second
}
}
Dev: Ok GCC, tell me what is wrong.
GCC: /home/whatever/project/TaxStorage.h:102: error: incompatible operand types ('const std::unordered_map<int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > >, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > > > > >::mapped_type' (aka 'const std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > >') and 'const std::pair<const int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > > >')
ДОКОЛЕ?!!
+1
#include <iostream>
#include <type_traits>
#include <utility>
#include <array>
template<size_t Size, typename T, typename FunctorType, size_t... idx>
constexpr std::array<decltype(std::declval<FunctorType>().operator()(std::declval<T>())), Size>
map_impl(const std::array<T, Size> & arr, FunctorType && f, std::index_sequence<idx...>)
{
return std::array{ f(std::get<idx>(arr))... };
}
template<size_t Size, typename T, typename FunctorType>
constexpr std::array<decltype(std::declval<FunctorType>().operator()(std::declval<T>())), Size>
map(const std::array<T, Size> & arr, FunctorType && f)
{
return map_impl(arr, f, std::make_index_sequence<Size>{});
}
struct MyFunctor {
constexpr float operator()(int arg)
{
return static_cast<float>(arg * arg) / 2.0f;
}
};
int main()
{
constexpr std::array arr{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
auto arrMappedFunctor = map(arr, MyFunctor{});
auto arrMappedLambda = map(arr, [](int x) constexpr { return static_cast<float>(x * x) / 2.0f; });
for (auto && x : arrMappedFunctor) {
std::cout << x << ' ';
}
std::cout << std::endl;
for (auto && x : arrMappedLambda ) {
std::cout << x << ' ';
}
std::cout << std::endl;
return 0;
}
0.5 2 4.5 8 12.5 18 24.5 32 40.5 50
0.5 2 4.5 8 12.5 18 24.5 32 40.5 50
Метушня выходит на новый уровень: полноценный map в compile-time. Поддерживает как ручные функторы с перегруженным operator(), так и constexpr-лямбды. При помощи небольшой модификации возможно реализовать поддержку кортежей с произвольными типами.
+1
Давайте течь от отступов и ругать код без оных.
+1
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#define next ;
#define zero 0
#define one 1
#define two 2
#define three 3
#define four 4
#define five 5
#define six 6
#define seven 7
#define eight 8
#define nine 9
#define dot .
#define begin {
#define end }
#define open (
#define close )
#define sqopen [
#define sqclose ]
#define less <=
#define xless <
#define greater >=
#define xgreater >
#define isnt !=
#define isequal ==
#define mustbe =
#define write cout
#define plus +
#define minus -
#define multi *
#define divby /
#define incr +=
#define decr -=
using namespace std next
string pswdGen open int quantity close begin
srand open time open 0 close close next
char chars sqopen sqclose mustbe "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890@\#\$\%\&\-\+\!\/\_" next
string password next
for(int i = zero next i xless quantity next i++) begin
password incr chars sqopen rand open close % open sizeof open chars close divby sizeof open *chars close close sqclose next
end
return password next
end
int main open close begin
int charNo next
write << "How many characters do you want in the password?" << endl next
cin >> charNo next
write << "Your new password is: " << pswdGen open charNo close << endl next
return zero next
end
По сути это тот же крестовый паролегенератор, но из-за дефайнов и от того символов можно отнести в кучу. И да, "Переведи на "зрз"" в сторону. Перевел вам за щеку, проверяйте
+1
let suffix = '';
if (search) {
if (filters.length) {
suffix = ' found:';
} else {
suffix = ' found';
}
} else {
if (filters.length) {
suffix = ' found:';
}
}
Когда не уверен, нужно двоеточие или нет.
+1
// NextViewController.swift
override func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
NSUserDefaults.standardUserDefaults().setInteger(indexPath.row, forKey: "Selected offense")
let offense: NSDictionary = self.offenses.objectAtIndex(indexPath.row) as NSDictionary
let id: Int = offense.objectForKey("id") as Int
let title: String = offense.objectForKey("title") as String
NSUserDefaults.standardUserDefaults().setInteger(id, forKey: "Selected offense id")
NSUserDefaults.standardUserDefaults().setObject(title, forKey: "Selected offense title")
}
// PreviousViewController.swift
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
hideKeyboard()
tableView.reloadData()
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let kCellIndetifier: String = "NewOffenseCell"
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIndetifier, forIndexPath: indexPath) as UITableViewCell
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: kCellIndetifier)
}
cell.text = NSUserDefaults.standardUserDefaults().stringForKey("Selected offense title")
cell.font = UIFont.systemFontOfSize(20)
return cell
}
Реализуем колбэки *лицорука*
+1
<?php
error_reporting(0);
ini_set('display_errors', '0');
mb_internal_encoding('UTF-8');
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/html; charset=utf-8');
$string=mb_strtolower(trim($_REQUEST['q']));
$string=str_replace('#', 'sharp', $string);
$string=str_replace('++', 'plusplus', $string);
preg_match_all('/(\w+)/u', str_replace('_', '', $string), $matches);
$words=$matches[1];
$bad=array();
$good=array();
foreach($words as $word){
if(mb_strpos($word, 'java')!==false || mb_strpos($word, 'джав')!==false || mb_strpos($word, 'ява')!==false){
if(mb_strpos($word, 'script')===false && mb_strpos($word, 'скрипт')===false){
$bad[]='Java';
}
}
if(mb_strpos($word, 'python')!==false || mb_strpos($word, 'питон')!==false || mb_strpos($word, 'пайтон')!==false){
$bad[]='Python';
}
if(mb_strpos($word, 'perl')!==false || mb_strpos($word, 'перл')!==false || mb_strpos($word, 'пёрл')!==false){
$bad[]='Perl';
}
if(mb_strpos($word, 'cplusplus')!==false || mb_strpos($word, 'сplusplus')!==false || mb_strpos($word, 'cpp')!==false){
$bad[]='C++';
}
if(mb_strpos($word, 'csharp')!==false || mb_strpos($word, 'сsharp')!==false || mb_strpos($word, 'сишарп')!==false || mb_strpos($word, 'сшарп')!==false){
$bad[]='C#';
}
if($word=='c' || $word=='си' || $word=='сях'){
$bad[]='C';
}
if(mb_strpos($word, 'haskel')!==false || mb_strpos($word, 'хаскел')!==false){
$bad[]='Haskell';
}
if(mb_strpos($word, 'pascal')!==false || mb_strpos($word, 'паскал')!==false){
$bad[]='Pascal';
}
if(mb_strpos($word, 'delphi')!==false || mb_strpos($word, 'delfi')!==false || mb_strpos($word, 'делф')!==false || mb_strpos($word, 'дельф')!==false){
$bad[]='Delphi';
}
if(mb_strpos($word, 'assembler')!==false || mb_strpos($word, 'asm')!==false || mb_strpos($word, 'ассемблер')!==false || mb_strpos($word, 'асм')!==false){
$bad[]='Assembler';
}
if(mb_strpos($word, 'ruby')!==false || $word=='руби' || mb_strpos($word, 'рубист')!==false || mb_strpos($word, 'рубях')!==false){
$bad[]='Ruby';
}
if(mb_strpos($word, '1c')!==false || mb_strpos($word, '1с')!==false || mb_strpos($word, '1ц')!==false){
$bad[]='1C';
}
if(mb_strpos($word, 'dart')!==false || mb_strpos($word, 'дарт')!==false){
$bad[]='Dart';
}
if(mb_strpos($word, 'linux')!==false || mb_strpos($word, 'линукс')!==false || mb_strpos($word, 'линух')!==false || mb_strpos($word, 'ubunt')!==false || mb_strpos($word, 'убунт')!==false || mb_strpos($word, 'debian')!==false || mb_strpos($word, 'дебиан')!==false || mb_strpos($word, 'freebsd')!==false || mb_strpos($word, 'фрибсд')!==false){
$bad[]='Linux';
}
if(mb_strpos($word, 'unix')!==false || mb_strpos($word, 'nix')!==false || mb_strpos($word, 'юникс')!==false || mb_strpos($word, 'юних')!==false){
$bad[]='Unix';
}
if(mb_strpos($word, 'jvm')!==false || mb_strpos($word, 'жвм')!==false){
$bad[]='JVM';
}
if(mb_strpos($word, 'jsharp')!==false){
$bad[]='J#';
}
if(mb_strpos($word, 'jplusplus')!==false){
$bad[]='J++';
}
if(mb_strpos($word, 'git')!==false || mb_strpos($word, 'гит')!==false){
if(mb_strpos($word, 'hub')===false && mb_strpos($word, 'хаб')===false && mb_strpos($word, 'lab')===false && mb_strpos($word, 'лаб')===false){
$bad[]='Git';
}
}
if(mb_strpos($word, 'svn')!==false || mb_strpos($word, 'свн')!==false){
$bad[]='SVN';
}
if(mb_strpos($word, 'postgres')!==false || mb_strpos($word, 'постгр')!==false || mb_strpos($word, 'pg_')!==false){
$bad[]='PostgreSQL';
}
if(mb_strpos($word, 'composer')!==false || mb_strpos($word, 'композер')!==false){
$bad[]='Composer';
}
if(mb_strpos($word, 'bower')!==false || mb_strpos($word, 'бовер')!==false || mb_strpos($word, 'бауэр')!==false || mb_strpos($word, 'боуэр')!==false){
$bad[]='Bower';
}
if(mb_strpos($word, 'node')!==false || mb_strpos($word, 'ноде')!==false || mb_strpos($word, 'нода')!==false){
$bad[]='NodeJS';
}
if(mb_strpos($word, 'php')!==false || mb_strpos($word, 'пхп')!==false || mb_strpos($word, 'пых')!==false || mb_strpos($word, 'пэхапэ')!==false || mb_strpos($word, 'похапэ')!==false || mb_strpos($word, 'пехапе')!==false || mb_strpos($word, 'похапе')!==false || mb_strpos($word, 'эйч')!==false || mb_strpos($word, 'пшп')!==false){
$good[]='PHP';
}
if(mb_strpos($word, 'mysql')!==false || mb_strpos($word, 'мускул')!==false || mb_strpos($word, 'майскул')!==false){
$good[]='MySQL';
}
if(mb_strpos($word, 'windows')!==false || mb_strpos($word, 'виндовс')!==false || mb_strpos($word, 'шинд')!==false || mb_strpos($word, 'винд')!==false){
$good[]='Windows';
}
}
+1
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
string pswdGen(int quantity) {
srand(time(0));
char chars[] = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890@\#\$\%\&\-\+\!\/\_"; // Символы, из которых будет состоять пароль
string password;
for(int i = 0; i < quantity; i++) {
password += chars[rand() % (sizeof(chars)/sizeof(*chars))]; // Добавить рандомный символ из списка в пароль
}
return password;
}
int main() {
int charNo;
cout << "How many characters do you want in the password?" << endl;
cin >> charNo;
cout << "Your new password is: " << pswdGen(charNo) << endl;
return 0;
}
Генерит произвольные пароли. Говно?