Skip to content

Instantly share code, notes, and snippets.

View Ronald-TR's full-sized avatar
:shipit:
Stealth

Ronald Ronald-TR

:shipit:
Stealth
View GitHub Profile
@FreeBirdLjj
FreeBirdLjj / switch.lua
Last active July 14, 2024 17:46
A way to write switch-case statements in lua.
print "Hello, switch"
-- If the default case does not have to be handled, we can use the following auxiliary function:
local function switch(value)
-- Handing `cases` to the returned function allows the `switch()` function to be used with a syntax closer to c code (see the example below).
-- This is because lua allows the parentheses around a table type argument to be omitted if it is the only argument.
return function(cases)
-- The default case is achieved through the metatable mechanism of lua tables (the `__index` operation).
setmetatable(cases, cases)
@cdiener
cdiener / asciinator.py
Last active January 5, 2023 17:24
Convert image to ascii art
import sys; from PIL import Image; import numpy as np
chars = np.asarray(list(' .,:;irsXA253hMHGS#9B&@'))
if len(sys.argv) != 4: print( 'Usage: ./asciinator.py image scale factor' ); sys.exit()
f, SC, GCF, WCF = sys.argv[1], float(sys.argv[2]), float(sys.argv[3]), 7/4
img = Image.open(f)
S = ( round(img.size[0]*SC*WCF), round(img.size[1]*SC) )
img = np.sum( np.asarray( img.resize(S) ), axis=2)
@claymcleod
claymcleod / pycurses.py
Last active July 20, 2024 00:12
Python curses example
import sys,os
import curses
def draw_menu(stdscr):
k = 0
cursor_x = 0
cursor_y = 0
# Clear and refresh the screen for a blank canvas
stdscr.clear()
@enginebai
enginebai / MainActivity.java
Last active July 27, 2021 11:10
Get the current location and display a marker on Google Map.
package com.enginebai.sample;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
@crgimenes
crgimenes / gates.lisp
Last active May 21, 2021 02:12
Creates a fake NAND gate and then creates all gates from NAND.
;;;; Creates a fake NAND gate and then creates all gates from NAND.
;;;; This is just an exercise, obviously has no practical application.
;;; NAND
(defun !& (a b) (if (and (= a 1) (= b 1)) 0 1))
;;; NOT
(defun ! (a) (!& a 1))
;;; AND