Skip to content

Instantly share code, notes, and snippets.

View jieniu's full-sized avatar
🎯
Focusing

jieniu jieniu

🎯
Focusing
View GitHub Profile
@jieniu
jieniu / curl proxy
Created June 15, 2020 14:28
curl proxy
1. You can make a alias in your ~/.bashrc file :
alias curl="curl -x <proxy_host>:<proxy_port>"
2. Another solution is to use (maybe the better solution) the ~/.curlrc file (create it if it does not exist) :
```
proxy = <proxy_host>:<proxy_port>
```
e.g.
```
@jieniu
jieniu / python_gist.py
Last active January 26, 2019 08:08
python gist
# mock side_effect
>>> iter_mock = mock.Mock(side_effect=[1, 2, 3])
>>> iter_mock()
1
>>> iter_mock()
2
>>> iter_mock()
3
# n days ago
@jieniu
jieniu / unsigned_long_string_parser.java
Created January 25, 2019 03:27
how to parse a unsigned long string
// "14714368837763236677" -> -3732375235946314939
long long_id = new BigInteger(str_id.trim()).longValue();
// -3732375235946314939 -> "cc33f07f74f48345"
String str_hex_id = Long.toHexString(long_id);
@jieniu
jieniu / gson_fromJson.java
Created January 15, 2019 11:46
gson->fromJson(List)
List<Student> retList = gson.fromJson(s2,
new TypeToken<List<Student>>() {
}.getType());
@jieniu
jieniu / inject_mock_object.java
Created January 12, 2019 04:01
inject mock object when ut
@RunWith(PowerMockRunner.class)
@PrepareForTest({DatasetInfoDao.class, DatasetResource.class})
public class DatasetResourceTest {
@Test
public void testIsDumpTimingValidTrue() throws Exception {
DatasetInfoDao dao = PowerMockito.mock(DatasetInfoDao.class);
PowerMockito.when(dao, "getCreatetimeByGroupIdAndDocName", Mockito.any(String.class), Mockito.any(String.class)).thenReturn(null);
DatasetResource resource = PowerMockito.spy(new DatasetResource());
MemberModifier.field(DatasetResource.class, "datasetInfoDao").set(resource, dao);
@jieniu
jieniu / mock_static.java
Created January 10, 2019 07:04
power mock static
@RunWith(PowerMockRunner.class)
@PrepareForTest(DriverManager.class)
public class Mocker {
@Test
public void testName() throws Exception {
//given
PowerMockito.mockStatic(DriverManager.class);
BDDMockito.given(DriverManager.getConnection(...)).willReturn(...);
@jieniu
jieniu / how-to-assert-exception.java
Last active January 10, 2019 07:49
java assert exception unitest
import static org.junit.jupiter.api.Assertions.assertThrows;
@Test
public void testUsernameIsNull() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
User user = new User();
user.setName(null);
});
Assert.assertEquals("expected message", exception.getMessage());
}
{"sig":"87058829e86fa3d345d0f72e6a72425c2ab8e60a29fdc2b03c43dc73d414c7ab25acf466e8a14fdefcaab8a07c2e5ff760b91642b878303f0d64d149bdc0c1a30","msghash":"4b3370128fe7e0899a9d23151ab0a425f296c2bda535470e7c1b3830c32e2826"}
{"sig":"87058829e86fa3d345d0f72e6a72425c2ab8e60a29fdc2b03c43dc73d414c7ab25acf466e8a14fdefcaab8a07c2e5ff760b91642b878303f0d64d149bdc0c1a30","msghash":"4b3370128fe7e0899a9d23151ab0a425f296c2bda535470e7c1b3830c32e2826"}
{"sig":"87058829e86fa3d345d0f72e6a72425c2ab8e60a29fdc2b03c43dc73d414c7ab25acf466e8a14fdefcaab8a07c2e5ff760b91642b878303f0d64d149bdc0c1a30","msghash":"4b3370128fe7e0899a9d23151ab0a425f296c2bda535470e7c1b3830c32e2826"}