contracts = Contract.objects.filter(staff=staff).filter(active=True)
if contracts.__len__() > 0:
   ind = contracts.__len__() - 1
   dic[‘active_contract_id’] = contracts[ind].id
else:
   dic[‘active_contract_id’] = contracts[0].id

Get last object of queryset in django

By itsN0ll, 2018-01-29 11:35:27
CREATE FUNCTION [dbo].[get_number_of_workers] 
(
     @number_of_workers varchar(10)
 
)
RETURNS int
AS
BEGIN
 
 
set @number_of_workers = replace(replace(replace(replace(LTRIM(RTRIM(@number_of_workers)), char(9), ''), char(10), ''), char(13),''), char(13)+char(10), '')
 
DECLARE @temp varchar(10)
 
SELECT
    @temp = number_of_workers 
FROM
    (SELECT LTRIM(RTRIM(@number_of_workers)) as number_of_workers) as temp
WHERE
       number_of_workers like  '[0-9]'
    or number_of_workers like  '[0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
    or number_of_workers like  '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
     
     
RETURN CONVERT(INT, @temp)
 
END
By Anonymous, 2015-07-22 14:59:09
const errorHandler = () => {
  throw new Error();
};
By Anonymous, 2018-10-08 19:35:38
        $gallery = \common\models\UtVideogallery::find()->select(['ut_videogallery.VideogalleryID',
                'ut_videogallery.Name_rus','ut_videogallery.TournamentID','ut_videogallery.MatchID', 'Slug',
                'ut_videogallery.Date','COUNT(ut_video_to_gallery.VideoToGalleryID) count','ut_matches_videos.Data',
                'm1.Data DataP'])
                ->leftJoin('ut_video_to_gallery','ut_video_to_gallery.VideogalleryID=ut_videogallery.VideogalleryID')
                ->leftJoin('ut_matches_videos','ut_matches_videos.VideoID=ut_video_to_gallery.VideoID')
                ->leftJoin('ut_matches_videos m1','m1.VideoID=ut_videogallery.PreviewID')
                ->where(['ut_videogallery.Active'=>1])
                //->andWhere(['TournamentID'=>$list['selected']])
                ->groupBy('ut_videogallery.VideogalleryID')
                ->orderBy('ut_videogallery.Date DESC')
                ->limit(self::$countPerPage)
                ->asArray()->all();
        foreach ($gallery as $key => $value) {
            if($value['count']==0) unset($gallery[$key]);
        }
        foreach($gallery as $k=>$v){
            if(isset($v['Data']))
                $v['Data'] = str_replace('http:','https:',$v['Data']);
            if(isset($v['DataP']))
                $v['DataP'] = str_replace('http:','https:',$v['DataP']);
            $gallery[$k]=$v;
        }
        $galleryCount = \common\models\UtVideogallery::find()->select(['ut_videogallery.VideogalleryID',
                'ut_videogallery.Name_rus','ut_videogallery.TournamentID','ut_videogallery.MatchID',
                'ut_videogallery.Date','COUNT(ut_video_to_gallery.VideoToGalleryID) count','ut_matches_videos.Data'])
                ->leftJoin('ut_video_to_gallery','ut_video_to_gallery.VideogalleryID=ut_videogallery.VideogalleryID')
                ->leftJoin('ut_matches_videos','ut_matches_videos.VideoID=ut_video_to_gallery.VideoID')
                ->leftJoin('ut_matches_videos m1','m1.VideoID=ut_videogallery.PreviewID')
                ->where(['ut_videogallery.Active'=>1])
                //->andWhere(['TournamentID'=>$list['selected']])
                ->groupBy('ut_videogallery.VideogalleryID')   
                ->orderBy('ut_videogallery.Date DESC')
                ->asArray()->all();
        foreach ($galleryCount as $key => $value) {
            if($value['count']==0) unset($galleryCount[$key]);
        }
        $pagination = new \yii\data\Pagination(
        [
            'totalCount' => count($galleryCount),
            'pageSize' => self::$countPerPage,

        ]);

Picasso of PHP

By chernomorets, 2017-03-03 11:26:18
let foo = {} // object no. 1
let bar = {} // object no. 2

foo > bar // return false
foo < bar // return false, so maybe foo equals bar?
foo == bar // oh well, return false
// but
foo >= bar // return true, 'cause !(foo < bar) == true

return value is expected, but JS is funny

By Anonymous, 2021-03-12 21:08:32
var query = $("#search-query");
query.click(function() {
  if (query.val() == 'szukaj...') {
     query.val('');
  }
});
By Kadet, 2016-02-14 14:54:32
public static bool HasValues<T>(this ICollection<T> collection)
{
    if (collection == null)
    {
        return false;
    }
    if (collection.Count == 0)
    {
        return false;
    }
    return true;
}
By oskarnrk, 2017-12-12 16:49:43
// TODO(as): MAKE XML DOXYGEN THING SO IDE WITH COLORS CAN READ THIS
package main

import (
	"os"
	"sync"

	_ "github.com/mailru/easyjson"
	_ "github.com/satori/go.uuid"
	_ "github.com/valyala/fasthttp"
)

func main() {
	sync.Once(func(){}())

	myMutexLockVariable := struct {
		IDontKnowHowEmbeddingWorks *sync.RWMutex // FOR SCALEABILITY
	}{
		func() *sync.RWMutex {
			return new(sync.RWMutex) // FACTORY PATTERN FACTORY PATTERN!
		}(),
	}
	
	lockthelock := func(){
		myMutexLockVariable.IDontKnowHowEmbeddingWorks.Lock()
	}
	unlockthelock := func(){
		myMutexLockVariable.IDontKnowHowEmbeddingWorks.Lock()
	}
	// TODO(as): THERE THEM FUNCTIORNS NO WORKY ABSTRACTION FOR SOME REASON
	// SO WE JUST CALL myMutexLockVariable.IDontKnowHowEmbeddingWorks FUNCTIONS
	// DIRECTLY THERE IS A BUG INSIDE OF THE GO PROGRAMMING LANGUAGE
	//
	// GO ISSUE NUMBER: 181393
	// Description: GO NO WORKY, I PUT FUNCTORS TO ACCESS MY LOCK AND IT DEAD LOCK
	// cc: bradfitz, ian lance taylor, rob pike, ken, even brian k
	lockthelock = lockthelock
	unlockthelock = unlockthelock
	    // I DONT WANNA DELETE FUNCY BECAUSE I WORK TOO HARD ON THEM WE KEEP IT FOR USE LATER WHEN GO FIXES BUG

	var err error
	if myMutexLockVariable.IDontKnowHowEmbeddingWorks == nil {
		panic("whoops, you forgot to put the pointer of the mutex!!!!!")
		os.Exit(0xbadc0de) // FOR SAFTEY
	}
	myMutexLockVariable.IDontKnowHowEmbeddingWorks.RLock()
	myMutexLockVariable.IDontKnowHowEmbeddingWorks.Unlock() // just grease the wheels a bit
	myMutexLockVariable.IDontKnowHowEmbeddingWorks.Lock()
	go func() {
		println("goroutine!")
		myMutexLockVariable.IDontKnowHowEmbeddingWorks.Unlock()
	}()

	myMutexLockVariable.IDontKnowHowEmbeddingWorks.Lock() // WAIT FOR BABY TO FINISH
	if &err != nil {
		myMutexLockVariable.IDontKnowHowEmbeddingWorks.Unlock() // DO IT HERE FASTER THAN DEFUR
		main()
		os.Exit(0) // YAY
	}
	myMutexLockVariable.IDontKnowHowEmbeddingWorks.Unlock() // DO IT HERE FASTER THAN DEFUR
}

THIS CODE IS COVERED BY THE GNU AFFERO PUBIC LICENSE, DO NOT SHARE THIS CODE WITHOUT PUBLISHING ALL OF YOUR CHANGES. FREE SOFTWARE FREEEEEDOM!!!

TO SEE THE TEXINFO MANUAL IN EMACS, TYPE CONTROL X CLOVER CLOVER DOT 9

By github.com/as, 2019-10-18 19:26:43
<?
function null($null) {
    return null;   
}
By SH2, 2018-02-20 11:31:33
<input type="button" value="Go and fill  later" onclick="javascript:window.location='<?php echo $url; ?>info.php'" />

Well, a is obsolete, let's do links as buttons!

By Anonymous, 2017-02-14 20:36:30
public enum YesNoEnum
{
	Yes = 0,
	No = 1
}

I also like how they defined the enum values.

By Anonymous, 2018-05-19 19:33:44
public boolean logout(String token)
{
    LogedUser user = logedUsers.remove(token);
    return (user != null) ? true : false;
}
By Slacki, 2015-11-17 17:58:53
    UIButton * btn = [UIButton new];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    //May god have mercy of me
    [[btn titleLabel] setFont:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium]];
    [btn setTitle:[NSString stringWithFormat:@"  %@  ", btnTxt] forState:UIControlStateNormal];
    [btn sizeToFit];
    [btn setTitle:btnTxt forState:UIControlStateNormal];

Why keep playing with label padding or insets when you can add spaces?

By Shy developer, 2017-12-12 14:32:37
        var validAccountData = account.email != nil
        validAccountData = account.firstName != nil
        validAccountData = account.lastName != nil
        
        if validAccountData {
            return account
        }
        
        return nil

Proper validation

By Anonymous, 2017-12-12 15:17:35
if( %rightBtnCmd $= "noButtons" )
{
    //do nothing, as there are no buttons   
}

proprietary script language.

By Anonymous, 2017-12-14 19:52:22