This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"errors" | |
"fmt" | |
"log" | |
"math/rand" | |
"runtime" | |
"strings" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
void* t_routine(void* args){ | |
unsigned int i = 0; | |
int a; | |
printf("Running thread!\n"); | |
for(i=0;i<4000000000;i++){ | |
a = 2*2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <time.h> | |
#include <math.h> | |
#include <assert.h> | |
// #define ARRAY_SIZE 100 | |
#define MAX_NUMBER 100 | |
#define bool char |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
int compare_int(void* va, void* vb){ | |
int* a = va; | |
int* b = vb; | |
return *b - *a; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reverses a string of space-separated words terminated by newline | |
#include <stdio.h> | |
#include <stdlib.h> | |
void swap(char* arr, int i, int j){ | |
char t = arr[j]; | |
arr[j] = arr[i]; | |
arr[i] = t; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A function that takes a list and a number. Returns the maximum number that is no larger than def_max. | |
""" | |
def bad_definedMax(in_array, def_max): | |
""" | |
O(N) (not counting the sorting) | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
number_pattern = r"(([1-9]?[0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))" | |
IP_validator = re.compile(r'^{0}(\.{0}){1}$'.format(number_pattern, "{3}")) | |
def is_valid_IP(strng): | |
return bool(IP_validator.match(strng)) | |
is_valid_IP("12.34.56.708") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
def split_list(alist,max_size=1): | |
"""Yield successive n-sized chunks from l.""" | |
for i in range(0, len(alist), max_size): | |
yield alist[i:i+max_size] | |
def toAscii85(data): | |
result = [] | |
for chunk in split_list(data, max_size=4): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctype.h> | |
#include <stdio.h> | |
#include <math.h> | |
double atod(char * s) | |
{ | |
int i; | |
for(i=0;isspace(s[i]);i++); | |
int sign = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int findPatternRight(char* s, char* pat){ | |
bool flag = true; | |
int i, j, k, left; | |
int len_s = strlen(s); |
NewerOlder