flowchart TD
A[Why do you want to learn programming?] -- Fun --> B[Simplicity or Efficiency?];
B -- Simplicity --> C[Is portability important?];
C -- Yes --> D{JS};
C -- No --> E[Aesthetics or Clearness?];
E -- Aesthetics --> F{Ruby};
E -- Clearness --> G[Ease or Versatility?];
G -- Ease --> H{Python};
G -- Versatility --> I{Lua};
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
# Inverse square root and fast inverse square root | |
from ctypes import c_long, c_float, addressof, cast, POINTER | |
def fisr(number: float) -> float: | |
y = c_float(number) | |
i = c_long(0x5f3759df - (cast(addressof(y), POINTER(c_long)).contents.value >> 1)) | |
y = cast(addressof(i), POINTER(c_float)).contents.value | |
return y * (3 - (number * y * y)) / 2 | |
""" | |
float fisr(float number) { | |
float y = number; |
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
# Stream movies from cmd for wsl (requires xlaunch and pulseaudio) | |
# Install requirements: sudo npm i peerflix -g && sudo apt install mpv -y | |
# Execute: bash stream.sh endgame | |
/mnt/c/pulseaudio/bin/pulseaudio.exe 2>/dev/null & export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 && sleep 1 && export PULSE_SERVER=tcp:$(grep nameserver /etc/resolv.conf | awk '{print $2}'); | |
peerflix -k $(curl -s https://1337x.wtf/$(curl -s https://1337x.wtf/search/$(printf '%s' "$*" | tr ' ' '+' )/1/ | grep -Eo "torrent\/[0-9]{7}\/[a-zA-Z0-9?%-]*/" | head -n 1) | grep -Po "magnet:\?xt=urn:btih:[a-zA-Z0-9]*" | head -n 1) > /dev/null |
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 sympy import * | |
N(summation(floor((n := symbols('n')) * tanh(pi)) / Pow(10, n), (n, 1, oo)) - 1 / S(81)) |
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
# Simple python shell | |
## Use: | |
### In cmd: | |
#### python3 shell.py | |
#### echo "ls" | python3 shell.py | |
### In python: | |
#### main("ls") | |
from os import name, popen, getcwd | |
from sys import stdin, exit | |
if name != 'nt': import readline |
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
// cute demo for line drawing in p5js | |
async function setup() { | |
createCanvas(400, 400); | |
background(0); | |
stroke(0, 200, 0); | |
fill(0, 200, 0); | |
const distance = 25; | |
for (var i = 0; i < 300 / distance + 1; i++) { | |
drawLine(new p5.Vector(50 + distance * i, 350), new p5.Vector(50 + distance * i, 50), 50, 1); | |
await drawLine(new p5.Vector(50, 350 - distance * i), new p5.Vector(350, 350 - distance * i), 50, 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
from os.path import isdir | |
def cpu_count() -> int: | |
i = 0 | |
while isdir('/sys/devices/system/cpu/cpu%d' % i): i += 1 | |
return i | |
def __check_cpu(i: int) -> None: | |
assert i < cpu_count(), "CPU index out of range" | |
assert isinstance(i, int), "CPU index must be an integer" | |
assert i > 0, "CPU 0 is always active and cannot be deactivated nor activated" | |
def cpu_active(i: int) -> bool: |
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
// alert the IP address | |
var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var pc = new myPeerConnection({iceServers: [{urls: 'stun:stun.l.google.com:19302'}]}), ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g; pc.createDataChannel(''); pc.createOffer(function(sdp) {pc.setLocalDescription(sdp, () => {}, () => {});}, () => {}); pc.onicecandidate = function(ice) {if (ice && ice.candidate && ice.candidate.candidate && ice.candidate.candidate.match(ipRegex)) alert('Your IP address is: ' + ice.candidate.candidate.match(ipRegex)[0]);}; |
#include <stdio.h>
int main() {
char a[6], *b = "test\n\0";
char *temp=a;while(*temp++=*b++);
printf("%s", a);
return 0;
}