Vue normale

À partir d’avant-hierFlux principal

Data to Fish: Data Science Tutorials using Python, SQL and more!

14 juillet 2020 à 11:01

Data To Fish was born in an effort to facilitate the application of data science using various tools such as Python, R, Julia and SQL.

We are passionate about data, and strive to provide you the most up-to-date and accurate information about common data-related problems.

The content provided on this website is constantly reviewed. Yet, if you do come across any errors in the content, please feel free to reach us at datatofish@gmail.com. Please note that due to the high volume of requests, we can no longer accommodate personal requests of code reviews. Please also refrain from including any email attachments.


Direct link

Pro-tip: Custom Editors in Unity

31 mars 2018 à 22:49
If you wanna make custom editors in Unity, be wary of the headaches.

That being said, you could always check the "newly" released Unity C# reference code on how they tackle their own Editors.

For instance, you see some fancy thing they did in their SpriteRenderer editor OnInspectorGUI, go look up the code and get inspired by their magic!
Permalink

Automate storing of Object given parameters at creation

28 janvier 2017 à 22:41
Basically replacing this

class A:
    def __init__(self, b, c, d, e):
        self.b = b
        self.c = c
        self.d = d
        self.e = e

by

class A:
    def __init__(self, b, c, d, e):
        # You can edit parameters' value here before they are being stored
       
        for k, v in vars().items():
            setattr(self, k, v)


By me.
Permalink

Debugging Python script more easily with Notepad++

25 juillet 2016 à 22:22
[path_to_script]\python-no-autoclose.py "$(FULL_CURRENT_PATH)"

In the menu  Run > Run, put this in the text field and hit Save, give it a name and a key combination. Personally I used Shift+F5. Be wary than all key combinations might not work, try it to make sure or change it.

The script:

import sys
import traceback
import subprocess
import os
import pathlib

if sys.argv[1:]:  # Failsafe
    try:
        os.chdir(str(pathlib.Path(sys.argv[1]).parent))
    except Exception as e:
        traceback.print_exc()

    try:
        subprocess.call(['python', sys.argv[1]])
    except Exception as e:
        traceback.print_exc()
else:
    print('I\'m very confused...')

print()
input('Press Enter to exit.')
Permalink

Easily compile some Java

5 juillet 2016 à 13:48
I don't have any experience with compiling Java so I'm just leaving this here for future me.

1) Download Java JDK (Any version should be fine)
2) If you're lucky to have a .gradle file in your app directory, download Gradle. (You can then add gradle to your PATH, but that's optional)
3) Go in the directory where your .gradle file is situated and run

PATH_TO_YOUR_GRADLE/bin/gradle build

4) The compiled .jar will be situated in build/libs

That's it!
Permalink

PHP Fun: Exceptions

15 mars 2015 à 06:22
Ils sont sympas sur le tchat PHP de SO.

Quelques amis m'ont donné des exemples de codes à propos des exceptions en PHP, que j'ai, un peu trop souvent rechigné.

C'est *bô*. Jugez-en par vous même:

http://3v4l.org/NJJjO

function (╯°□°)╯︵┻━┻(){throw new ┻━┻;}
class ┻━┻ extends  Exception {public function __construct() {parent::__construct("Please respect tables! ┬─┬ノ(ಠ_ಠノ)");} public function __toString(){return "┬─┬";}}
// try/catch
try { (╯°□°)╯︵┻━┻ (); } catch ( ┻━┻ $niceguy) {echo $niceguy->getMessage();}
// ok now lets see an uncaught one
(╯°□°)╯︵┻━┻
();

// Output:
Please respect tables! ┬─┬ノ(ಠ_ಠノ)
Fatal error: Uncaught ┬─┬


Et http://3v4l.org/TkNpc

class JeromeException extends Exception
{
    protected $boobies = [];
   
    function __construct($message = null, $code = 0, Exception $previous = null, $arrayOfBoobies = [])
    {
        $this->boobies = $arrayOfBoobies;
    }
   
    function getTraceEx()
    {
        return $this->getTrace() + ['boobies' => $this->boobies];
    }
}

function jeromeIsExceptional()
{
    try {
        throw new JeromeException('herro', 0, null, ['34B', '32C', '36D']);
    }
    catch (JeromeException $e) {
        var_dump($e->getTraceEx());
    }
}

jeromeIsExceptional();
Permalink

Signing data with HMAC - sebsauvage.net- Snyppets - Python snippets

27 novembre 2014 à 19:25
Bon, sachant que sebsauvage lit rarement ses mails, je vais tenter de le contacter par ici. :)

Ton implémentation est non sécurisée. C'est mal car d'autres personnes risquent de s'en inspirer sans savoir les problèmes liés à cette implémentation.

1) " Warning - When comparing the output of hexdigest() to an externally-supplied digest during a verification routine, it is recommended to use the compare_digest() function instead of the == operator to reduce the vulnerability to timing attacks." https://docs.python.org/3.4/library/hmac.html#hmac.HMAC.hexdigest

2) "The digestmod argument to the hmac.new() function may now be any hash digest name recognized by hashlib. In addition, the current behavior in which the value of digestmod defaults to MD5 is deprecated: in a future version of Python there will be no default value. (Contributed by Christian Heimes in issue 17276.)" https://docs.python.org/3/whatsnew/3.4.html#hmac
Donc il faudrait mieux commencer à spécifier une valeur pour digestmod.

Comme suggéré par l'issue (1) et cette réponse sur SO (2), je proposerais d'utiliser SHA-256 ou SHA-512 comme suit :

hmac.compare_digest(hmac.new(key, name, digestmod=hashlib.sha256).hexdigest(), signature)

(+ remplacer partout où il faut bien sure et ne pas oublier import hashlib)

(1) https://bugs.python.org/issue17276
"As of now the hash algorithm for HMAC defaults to MD5. However MD5 is considered broken. HMAC-MD5 is still ok but shall not be used in new code. Applications should slowly migrate away from HMAC-MD5 and use a more modern algorithm like HMAC-SHA256.

Therefore I propose that default digestmod should be deprecated in Python 3.4 and removed in 3.5. Starting with Python 3.5 developer are forced to choose a hash algorithm like SHA256. Our documentation shall suggest it, too."

(2) http://crypto.stackexchange.com/a/9340/18518
"Yes, there are currently no known attacks on HMAC-MD5.

[…]

However, this does not mean you should use HMAC-MD5 in new cryptosystem designs. To paraphrase Bruce Schneier, "attacks only get better, never worse." We already have practical collision attacks for MD5, showing that it does not meet its original security goals; it's possible that, any day now, someone might figure out a way to turn those into a preimage attack, which would compromise the security of HMAC-MD5. A much better choice would be to use HMAC with a hash function having no known attacks, such as SHA-2 or SHA-3."
Permalink

Security: HTML password input

18 octobre 2014 à 19:06
So, except few exceptions, almost all passwords shouldn't have "any" limit on the size of them upward (= no maximum length). Riiiight? :)
(Since they aren't supposed to be stored in raw form anyway and most (if not all?) hashing algorithm accept any size of password and always return unique constant length string)

So why HTML doesnt prevent bad ideas to be working? Like setting a maximum length on a password input… The way I see it, that would just not work and be reported in the console for debbugging purpose.

For the things I, so called "exceptions", I was thinking about PIN codes for instance. I could imagine letting HTML implements a new tag (or a new type of input tag) allowing a max length, but surely it would surely be abused though… Maybe those "PIN code" input should allow one fixed-length of password (as expected from a PIN code anyway and that would induce way less abuse too):

Finally, my browser (maybe some others too, mine is currently Palemoon, a implementation of Firefox) only prevent me to type more characters when I reach the maximum allowed by max-length, …, it doesnt warn me, it does nothing but preventing… The problem is that, if it was plain text, I could notice it easily, but as it is a password input and that my password is longer than the visible length of the field, then I have no fucking clue that what I'm currently typing is thrown away as I type it… -_-
So, some fucking warning would be appreciated at least!
Permalink

JS Libs for games

16 septembre 2014 à 20:02
Ouuh, de chouettes infos que nous avons là. :o

Hop je pause ça là pour plus tard

[22:00:13] Lunatick: En gros Kineticjs => control du canva en génial, fonction avancées, events de tout types (click, touch) géré nativement
[22:00:13] Lunatick: et Tweenmax ça permet d'animer n'importe quel valeur numérique sur le temps, un peu comme une transition CSS mais sur ce qu'on veut
[22:00:28] Lunatick: donc la Combinaison de Kineticjs + GSAP Tweenmax = des animation/jeu en js fluides et simple à écrire
[22:00:28] Lunatick: L'avantage de Tweenmax c'est aussi que n'importe quoi peut etre animé, exemple ça peut etre la largeur d'un élément du DOM, un nombre lambda ou les prop de n'importe quel objet
[22:03:41] Lunatick: avec en prime une la possibilité d'appeler une fonction en callback au début, à la fin, et à chaque mise a jour de l'item que tu "animes"
Permalink

ZeroBin : Quick (very) dirty hack to automate adf.ly, mediafire and mega downloads (Less clicks)

13 septembre 2014 à 19:51
J'avais commencé par faire le tout avec GreaseMonkey mais j'ai eu des probs avec le setTimeout tué par GreaseMonkey.

Du coup, j'ai fais un code très rapide en PHP; Il est fonctionnel (c'était le but).

Mais pour MEGA, le téléchargement coince à la fin, sûrement un prob de compatibilité du au domaine différent (127.0.0.1 dans mon cas).
Du coup Oros m'a aidé à résoudre le problème GreaseMonkey - je n'ai toujours pas compris pourquoi son code fonctionne et pas le mien, … mais au moins son code fonctionne! :

window.setTimeout('function wait() {if(document.getElementsByClassName("new-download-red-button").length==0){setTimeout("wait()",1000);}else{document.getElementsByClassName("new-download-red-button")[0].click();}}wait();', 1000);

Source: https://www.ecirtam.net/links/?XoFKOQ

Ça pourrait sûrement très facilement être entièrement porté à GreaseMonkey du coup …

Pour finir, dans mon cas, pour que ça reste quand même "pratique" (car au moins avec greaseMonkey, aucun clic requis), j'ai, personnellement, tout plein de pages bourrées de ces liens, donc j'ai un quick snippet pour changer tous les liens de la page pour qu'ils passent tous via mon script, et lorsqu'un cas n'est pas géré, mon script redirige vers la page normal.

javascript:var%20links=document.getElementsByTagName('a');for(var%20i%20=%200;%20i%20<%20links.length;%20i++){void(links[i].href%20=%20'http://127.0.0.1/test.php?url='+links[i].href);}
Permalink
❌
❌