Skip to content

Instantly share code, notes, and snippets.

View TwiN's full-sized avatar
Extremely busy

TwiN

Extremely busy
View GitHub Profile
@TwiN
TwiN / nameGenerator.php
Created January 10, 2016 23:40
Generates random names and puts them in a .txt file
<?php
//Generates random names and puts them in a txt file
$fileName = 'nameDatabase.txt';
$mode = 2; //MODE 1: array of names || MODE 2: one name per line
$amountOfNames = 100; //Amount of names to be generated
$startTime = microtime(true); //Starts timer
$adjs = array(
'Impressive',
'Overwhelming',
@TwiN
TwiN / [JAVA]bubbleSort.java
Created March 26, 2016 23:01
Java bubbleSort
public static void bubbleSort(int[] myList) { //USE: bubbleSort(myArray);
boolean flag = true;
while(flag) {
flag = false;
for(int i = 0; i < myList.length -1; i++) {
if(myList[i] < myList[i+1]) { // swap < for > to change from ascending to descending
int temp = myList[i];
myList[i] = myList[i+1];
myList[i+1] = temp;
flag = true;
@TwiN
TwiN / [JAVA]quickSort.java
Created March 26, 2016 23:02
Java quick sort
public static void quickSort(int myList[], int left, int right) {
int temp, i = left, j = right;
int pivot = myList[(left+right)/2];
do {
while(myList[i] < pivot) i++;
while(pivot < myList[j]) j--;
if (i <= j) {
temp = myList[i];
myList[i] = myList[j];
myList[j] = temp;
@TwiN
TwiN / .vimrc
Last active December 26, 2016 20:40
set nocompatible
" checks if pathogen is installed and run it if it is
if !empty(glob("/root/.vim/autoload/pathogen.vim"))
execute pathogen#infect()
let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
endif
" enables syntax highlighting by default.
if has("syntax")
#!/bin/bash
#NOTE:
#
# Une connection internet est necessaire pour le bon
# fonctionnement du script, mais meme sil n y a pas
# de connection internet, vous allez pouvoir entrer
# la temperature manuellement.
#
@TwiN
TwiN / fizzbuzz.cpp
Last active May 19, 2016 23:40
my version of fizzbuzz in C++
#include "stdafx.h"
#include "iostream"
using namespace std;
int main()
{
for (int i = 0; i < 101; i++) {
if (i % 3 == 0 ^ i % 5 == 0) { // can't be both
cout << (i % 3 == 0 ? "fizz" : "buzz") << endl;
@TwiN
TwiN / baseInstall.sh
Created May 21, 2016 16:40
First file I run when I install a ubuntu vm/vps
#!/bin/bash
echo "Updating.."
sudo apt-get update &> /dev/null
echo "Installing build-essential.."
sudo apt-get install build-essential &> /dev/null
echo "Installing python2.7-dev.."
sudo apt-get install python2.7-dev &> /dev/null
echo "Installing git.."
sudo apt-get install git &> /dev/null
echo "Installing vim.."
public static boolean isInList(String[] myList, String element) {
for(String s: myList) {
if (s.equals(element)) { return true; }
}
return false;
}
public static boolean isInList(char[] myList, char element) {
for(char c: myList) {
if (c == element) { return true; }
}
for i in range(101):
if i==0: continue
if (i%3==0) ^ (i%5==0):
print "fizz" if i%3==0 else "buzz"
elif i%3==0:
print "fizzbuzz"
else:
print i
@TwiN
TwiN / [PYTHON]file_get_contents(URL).py
Last active August 22, 2022 22:44
Python equivalent of PHP's file_get_contents on websites (NOT LOCAL FILES)
import urllib2,cookielib
'''
Function that returns the source from the target url
@param url
'''
def file_get_contents(url):
url = str(url).replace(" ", "+") # just in case, no space in url
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',