Skip to content

Instantly share code, notes, and snippets.

@shichao-an
shichao-an / keybase.md
Created June 5, 2020 04:13
keybase.md

Keybase proof

I hereby claim:

  • I am shichao-an on github.
  • I am shichaoan (https://keybase.io/shichaoan) on keybase.
  • I have a public key whose fingerprint is 9547 1ADF DFE5 3DBC A547 EA7E 7EC8 C7F8 8037 E444

To claim this, I am signing this object:

@shichao-an
shichao-an / gist:8992bd6e03582dc474f5d86b6b2aa440
Last active March 29, 2019 02:43 — forked from psayre23/gist:c30a821239f4818b0709
Runtime Complexity of Java Collections
Below are the Big O performance of common functions of different Java Collections.
List | Add | Remove | Get | Contains | Next | Data Structure
---------------------|------|--------|------|----------|------|---------------
ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array
LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List
CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array
@shichao-an
shichao-an / tmpdownloads.plist
Created April 24, 2018 00:56
Create a Downloads directory on macOS startup/login
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.loginscript</string>
<key>ProgramArguments</key>
<array>
<string>/bin/mkdir</string>
<string>-p</string>
<string>/private/tmp/Downloads</string>
</array>
@shichao-an
shichao-an / evdn3.md
Last active March 10, 2017 07:16
English Vocabulary Digest Note 3
  • cringe (vi.) 畏缩; 感到难堪
  • antics (n.) 滑稽的举止
  • nuts and bolts (n.) 基础部分; (adj.) 有关具体细节的
  • innuendo (n.) 暗示; 影射
  • demoralize (vt.) 使泄气
  • endearment (n.) 爱慕
  • outnumber (vt.) 在数量上超过
  • drool (vi.) 淌口水; 垂涎
  • chastise (vt.) 责备
  • whine (vt.) 哭喊
#include <stdio.h>
#include <stdlib.h>
#define test(x) ({ \
typeof(x) _x = (x); \
_x += 1; \
_x; \
})
int main(int argc, char* argv[])
@shichao-an
shichao-an / bit_field.c
Created April 27, 2016 05:50
Bit fields
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
struct
{
bool a: 1;
bool b: 1;
@shichao-an
shichao-an / flexible_array_member.c
Last active April 15, 2016 06:59
Flexible array member
#include <stdio.h>
#include <stdlib.h>
typedef struct string
{
int length;
char chars[];
} string;
int main(int argc, char * argv[])
@shichao-an
shichao-an / struct_offset.c
Created April 15, 2016 05:27
Get offsets of struct members using offsetof
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int x;
short y[3];
long long z;
} data_t;
@shichao-an
shichao-an / array-params.c
Created March 2, 2016 07:56
Arrays as function parameters in C
#include <stdio.h>
#include <stdlib.h>
/* the array name by default is a pointer to its first element,
* similar to test2
*/
void test1(int len, int x[])
{
int i;
for (i = 0; i < len; i++)
@shichao-an
shichao-an / sbcsucks.sh
Last active February 25, 2016 07:53
sbcsucks.sh
#!/usr/bin/env bash
# Check if SBC is stable and send a notification
OUTSIDE_HOST="${1:-8.8.8.8}"
PING_COUNT=15
PING_TIMEOUT=15
PING_INTERVAL=0.5
ASC_MBP="10.0.1.10"
STATUS="unknown"