Skip to content

Instantly share code, notes, and snippets.

View lovasoa's full-sized avatar
🎯
Focusing

Ophir LOJKINE lovasoa

🎯
Focusing
View GitHub Profile
@lovasoa
lovasoa / plot.coffee
Last active August 29, 2015 13:57
Plot a mathematical function in the terminal. In one line of coffeescript.
#Enter this line in the REPL coffeescript console
plot = (f,a,b) -> ((if 0<=n<75*f(i) or 75*f(i)<n<0 then '█' else ' ') for n in [-75..75]).join '' for i in (i for i in [a..b] by 0.05)
#Then, you can start plotting functions
plot Math.sin, 0, 2*Math.PI
@lovasoa
lovasoa / mixin.coffee
Last active August 29, 2015 13:57
Small coffeescript mixin function. Allows multiple inheritance.
mixIn = (classes...) ->
classes.reduce ((o,n) -> o::[key]=method for key,method of n::;o), (class)
@lovasoa
lovasoa / UTF8byteLength.js
Created April 27, 2014 23:23
Compute the length in bytes of a javascript string, when encoded in UTF8
function byteLength(str) {
// returns the byte length of an utf8 string
var s = str.length;
for (var i=str.length-1; i>=0; i--) {
var code = str.charCodeAt(i);
if (code > 0x7f && code <= 0x7ff) s++;
else if (code > 0x7ff && code <= 0xffff) s+=2;
if (code >= 0xDC00 && code <= 0xDFFF) i--; //trail surrogate
}
return s;
@lovasoa
lovasoa / README.md
Last active August 29, 2015 14:01
bug in emscripten
@lovasoa
lovasoa / syntax.cs
Last active August 29, 2015 14:02
My first program in csharp. Explores the power of the english syntax.
using System;
using System.Collections.Generic;
class HelloWorld
{
public static string NestedWithList (string[] subject, string[] verb) {
// Hey, I can haz lists!
List<string> sentence = new List<string>();
for (var i=subject.Length-1; i>=0; i--) {
sentence.Insert(0, subject[i]);
@lovasoa
lovasoa / seedcodes.txt
Created June 6, 2014 03:01
Maple FLEXlm seed codes
Seed code 1: 0x00518240
Seed code 2: 0xffffc380
@lovasoa
lovasoa / count.js
Last active August 29, 2015 14:05
Count nodes in a page in javascript
// This beautiful oneliner is a recursive function that counts the nodes in a given node
// It uses the ES6 "=>" notation for anonymous functions
var count = (node) => 1 + Array.prototype.slice.apply(node.childNodes).reduce((p,q) => count(q)+p, 0);
// Count the number of nodes in the current document
count(document);
@lovasoa
lovasoa / game.html
Last active July 27, 2016 17:57
Unfinished HTML5 game that uses the Gamepad API. The whole game is rendered in an HTML5 <SVG> element.
<!doctype html>
<html>
<head>
<meta charset="utf8">
<title>Turfu</title>
<style>
body{
background-color:black;
}
svg{
@lovasoa
lovasoa / bignum.rs
Last active August 29, 2015 14:07
Managing large numbers in rust
extern crate time;
use std::fmt;
#[deriving(Clone)]
struct BigNum {
val: Vec<u8>,
base: u8,
}
impl BigNum {
@lovasoa
lovasoa / LinkedList.rs
Last active March 13, 2018 17:47
Basic linked list implementation in Rust
enum List<T> {
Cons(T, Box<List<T>>),
Nil,
}
struct ListIterator<'a, T:'a> {
cur: &'a List<T>
}
impl<'a, T> Iterator<&'a T> for ListIterator<'a, T> {