S

@supriyo_biswas

Arrays: initializer lists for two-dimensional arrays

C
6 years ago
#include <stdio.h> int main() { // declare and initialize the array int a[2][3] = {{10, 20, 30}, {40, 50, 60}}; // declare loop variables int i, j; // print the values

Arrays: Reading user-entered numbers into a 2D array

C
6 years ago
#include <stdio.h> int main() { // declare a two-dimensional array, and variables // for the number of rows and columns. there are // also two loop variables i and j. int a[10][10], rows, cols, i, j; printf("Enter the number of rows:\n"); scanf("%d", &rows);

Arrays: Linear search

C
6 years ago
#include <stdio.h> int main() { // declare an array, a loop variable, and the number to search int a[5], i, search; // declare another variable to keep track of the index where // the number was found. int pos = -1;

Arrays: Reading user-entered numbers into an array

C
6 years ago
#include <stdio.h> int main() { // declare an array and a loop variable. int a[5], i; printf("Enter five numbers:\n"); // read each number from the user for (i = 0; i < 5; i++) {

Arrays: looping over an array

C
6 years ago
#include <stdio.h> int main() { // initialize an array int a[6] = {10, 20, 30, 40}; // initialize the loop variable int i; for (i = 0; i < 4; i++) {

Arrays: initializer lists smaller than the array size

C
6 years ago
#include <stdio.h> int main() { // the array size is 6, but only 4 elements are // there in the initializer list int a[6] = {10, 20, 30, 40}; // print the elements. the last two will be zero. printf("%d %d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4], a[5]);

Arrays: initializer lists

C
6 years ago
#include <stdio.h> int main() { // declare and initialize an array with an // initializer list int a[4] = {10, 20, 30, 40}; // print the elements printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]);

Arrays: initialization and usage

C
6 years ago
#include <stdio.h> int main() { // declare an array of size 4 int a[4]; // storing integers in the array a[0] = 10; a[1] = 20; a[2] = a[1] / a[0]; // a[2] will be set to 20/10 = 2

Implementing Python's "timeit" with PHP

PHP
6 years ago
<?php function timeit(callable $func, array $args, int $times = 50000) { if ($times < 1) { throw new InvalidArgumentException('times must be greater than 1'); } $total = 0;

Longest common subsequence

NodeJS
6 years ago
function lcs(s1, s2) { let m = Array(s2.length + 1).fill(null).map(() => Array(s1.length + 1).fill(null)); for (let i = 0; i <= s1.length; i += 1) { m[0][i] = 0; } for (let i = 0; i <= s2.length; i += 1) { m[i][0] = 0; }

Dependency injection in Python

Python
6 years ago
import inspect class ContainerDefinition: __slots__ = 'val', def __init__(self, val): self.val = val class Container: def __init__(self):

Exception behaviour test

PHP
6 years ago
<?php class Foo { function doSomething() { $lastException = null; foreach (range(0, 10) as $i) { try {

dlopen/dlsym hello world (todo)

C
6 years ago
#include <stdio.h> #include <dlfcn.h> int main(void) { void *h = dlopen(NULL, RTLD_LAZY); ((int (*)(char *)) dlsym(h, "puts"))("Hello, world!"); dlclose(h); return 0; }

Quick implementation of Unix commands with Python

Python
6 years ago
def ps(): import os, re for i in os.listdir('/proc'): if i.isdigit(): try: with open('/proc/%s/cmdline' % i) as f: cmd = re.sub('[\0\s]+', ' ', f.read()) print('%5s %s' % (i, cmd)) except OSError:

An extended JSON parser implemented as a recursive descent parser

Python
6 years ago
#!/usr/bin/env python3 class ParseError(Exception): def __init__(self, pos, msg, *args): self.pos = pos self.msg = msg self.args = args def __str__(self): return '%s at position %s' % (self.msg % self.args, self.pos)

Calculator implemented as a recursive descent parser

Python
6 years ago
#!/usr/bin/env python3 class ParseError(Exception): def __init__(self, pos, msg, *args): self.pos = pos self.msg = msg self.args = args def __str__(self): return '%s at position %s' % (self.msg % self.args, self.pos)