Skip to content

Instantly share code, notes, and snippets.

View anonur's full-sized avatar
🎯
Focusing

Onur Aydoğdu anonur

🎯
Focusing
View GitHub Profile
#include<stdio.h>
/* global variable declaration */
int g;
int main() {
/* local variable declaration */
int a,b;
#include<stdio.h>
/* function declaration */
int max(int num1, int num2);
int main() {
/* local vaariable definiton */
int a = 100;
int b = 200;
@anonur
anonur / loop-slice.py
Created April 4, 2019 19:21
Loop over a slice copy of the entire list with insert() function
words = ['cat', 'dog', 'people']
for w in words:
if len(w) > 6:
words.insert(0, w)
@anonur
anonur / while-measure-string.py
Created April 4, 2019 19:01
Measure strings with while loop and len() function
#Measure some strings:
movie = ['boogeyman', 'johnwick', 'best']
for m in movie:
print(m, len(m))
@anonur
anonur / success_test.sh
Created March 25, 2019 10:58
Tests if the given command executed successfully.
#!/bin/bash
#Filename: success_test.sh
CMD="command" #Substitute with command for which you need to test the exit status
$CMD
if [ $? -eq 0 ];
then
echo "$CMD executed successfully"
else
echo "$CMD terminated unsuccessfully"
fi
@anonur
anonur / sleep.sh
Last active March 25, 2019 11:00
Counting to the given number until it sleeps.
#!/bin/bash
#Filename:sleep.sh
echo -n Count:
tput sc #Store the cursor position.
count=0;
while true;
do
if [ $count -lt 40 ] ;
@anonur
anonur / num_sort.plx
Last active March 25, 2019 11:01
Number comparison by sort() function
#!/usr/bin/perl
#num_sort.plx
use warnings;
use strict;
my @unsorted = (1, 2, 11, 24, 3, 36, 40, 4);
my @string = sort { $a cmp $b } @unsorted; #with cmp, we compare $a and $b variables.
print "String sort: @string\n";
my @number = sort { $a <=> $b } @unsorted; # <=> helps us to sorting numbers.
@anonur
anonur / sort_names
Created February 19, 2019 16:13
Just a little sorting program
#!/usr/bin/perl
#sort_names.plx
use warnings;
use strict;
my @unsorted = qw(Onur Aylin Ayvaz Ferrin);
print "Unsorted: @unsorted\n";
my @sorted = sort @unsorted; #sort function puts the words in an alphabetical order.
print "Sorted: @sorted\n";
@anonur
anonur / commission calculator.c
Last active April 4, 2019 19:03
Calculates the commission
#include<stdio.h>
int main()
{
float sales;
float salary;
while(sales != -1) {
printf("Enter sales in dollars (-1 to end): ");
scanf("%f",&sales);
@anonur
anonur / factorial.c
Last active April 4, 2019 19:04
Simple code for finding a factorial
#include<stdio.h>
int main()
{
int n;
int fact = 1;
printf("Enter an integer that you want to take the factorial of: ");
scanf("%d",&n);