Skip to content

Instantly share code, notes, and snippets.

View seLain's full-sized avatar
😭
life is tough

Victor Hu seLain

😭
life is tough
  • Backend@TripPlus.cc
  • New Taipei City, Taiwan
View GitHub Profile
@seLain
seLain / AESCipher.py
Last active October 7, 2017 13:35 — forked from mguezuraga/AESCipher.py
Encrypt & Decrypt using PyCrypto AES 256From http://stackoverflow.com/a/12525165/119849
#!/usr/bin/env python
import base64
from Crypto import Random
from Crypto.Cipher import AES
import hashlib
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
@seLain
seLain / gist:2d6c234b93e3d4a8398f15a3a89327f2
Created November 14, 2017 09:09
manual openproject mysql db backup
# applied when back up through 'sudo openproject run backup' not working due to access denied 1045 issue
# using mysqldump instead. be sure to replace 'BACKUP_PATH/backup.sql' with desired baclup file location.
sudo mysqldump --single-transaction --add-drop-table --add-locks --result-file=BACKUP_PATH/backup.sql --host=localhost --user=openproject --password openproject
@seLain
seLain / gist:30fc906706997fec64a1a54c0b00c893
Created January 27, 2018 15:39
prevent java.lang.String.split() from creating leading or trailing empty string
/*
example delimiters : [ !,?._'@] (including space)
*/
String[] tokens = s.replaceFirst("^[ !,?._'@]+", "").split("[ !,?._'@]+");
// to keep leading empty string
String[] tokens = s.split("[ !,?._'@]+");
// to keep trailing empty string
@seLain
seLain / gist:43916f633fb6dde12eca7329dc1687a1
Created January 28, 2018 06:39
regular expression for IPv4 validation (demo with Java code)
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Scanner;
class Solution{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
String IP = in.next();
@seLain
seLain / gist:1d54e80d16b6ad59122d3f1d4ddf15df
Created February 24, 2018 04:05
set up a fetch-only remote
ref: http://sushihangover.github.io/git-set-up-a-fetch-only-remote/
> git remote -v # to see all remotes
> git remote set-url --push <remote_name> DISABLE
for example:
> git remote set-url --push upstream DISABLE
check again by
> git remote -v
@seLain
seLain / gist:a29a921ad76ad36a87d827f10df35dbe
Last active February 24, 2018 04:08
fork sibling repo as a branch and send pull request through github
say you have ...
- upstream : https://github.com/xxxxx/project_a.git
- origin : https://github.com/yourself/fork_project_a.git
and there is a sibling project : https://github.com/community_contributor/fork_project_a.git
1. get into your git bash under fork_project_a
2. add sibling project as new remote:
git remote add community_contributor https://github.com/community_contributor/fork_project_a.git
3. git fetch (to update and also make sure new remote added)
@seLain
seLain / gist:a09ba6df2be3f0b5798bb076a7d8adb1
Last active March 6, 2018 07:20
Django field validation before save
- Django does not automatically check max_lenght limitation before save()
- Django does not automatically check choices before save() --> it's for form
for the length limitation, using
datamodel.full_clean()
datamodel.save()
can resolve it. or, override save() to enforce full_clean()
ex:
@seLain
seLain / gist:5e56475dd59024eb47df01acaa04ccae
Created March 16, 2018 03:22
Django get new random secret key
This can be done in interactive python shell
> from django.core.management.utils import get_random_secret_key
> get_random_secret_key()
@seLain
seLain / gist:92938d7eb4e122502f005b34d51abe1b
Created August 7, 2018 14:39
Create PR with specific commit
git fetch --all # or whatever to make sure your repo consistent with origin
git checkout -b new_branch_for_single_change upstream/master # or origin mater, dependes where's your base source
git cherry-pick hashcode_of_specific_commit
git push -u origin new_branch_for_single_change # push this new branch to origin
then create PR from new_branch_for_single_change branch on origin to upsteam
@seLain
seLain / gist:688fab5bef49a94cce4a8e40bfb4fe4c
Created August 19, 2018 00:35
Checkout specific PR and push as new branch
https://help.github.com/articles/checking-out-pull-requests-locally/
checkout from origin
git fetch origin pull/ID/head:BRANCHNAME
git checkout BRANCHNAME
<do modifications>
<add>
<commit>
git push origin BRANCHNAME