Skip to content

Instantly share code, notes, and snippets.

@exavolt
exavolt / lagrangepolynomial.js
Created December 27, 2010 23:31
A class to perform Lagrange polynomial interpolation from a set of points
var LagrangePolynomial = (function(points){
var cc = {};
cc.points = points;
cc.calc = (function(x){
var n = this.points.length;
var y = 0.0;
var j = 0;
var k = 0;
var Lx = 1.0;
@exavolt
exavolt / mentionify.py
Created January 19, 2011 16:30
Simple Twitter like mention with RegEx
import re
_user_re = re.compile(r"""\B@([0-9a-zA-Z_]+)""")
def mentionify(text)
return _user_re.sub(r'@<a href="/user/\1">\1</a>', text)
@exavolt
exavolt / urlify.py
Created January 19, 2011 16:37
The name says...
#!/usr/bin/env python
import cgi
import re
import elml
def _urlify_re_proc(match):
#TODO: Truncate the display text for long URLs. e.g.:
@exavolt
exavolt / amazon_sender.py
Created January 21, 2012 02:17 — forked from amix/amazon_sender.py
Amazon SES helper script using boto
# -*- coding: utf-8 -*-
"""
amazon_sender.py
~~~~~~~~
Python helper class that can send emails using Amazon SES and boto.
The biggest feature of this class is that encodings are handled properly.
It can send both text and html emails.
This implementation is using Python's standard library (which opens up for a lot more options).

Di sini kita akan membahas seputar pergerakan object di dalam game yang digerakkan dengan cara mengklik titik tujuan kemana object harus bergerak. Cara input seperti ini banyak digunakan untuk game-game RTS dan RPG.

Secara garis besar bisa kita jelaskan sebagai: menggerakkan object ke arah yang dituju. Cukup simpel. Tapi kalo menggampangkan, hasilnya tidak seperti yang kita harapkan; misal, ketika sampai di tujuan, object-nya bergerak bolak-balik.

Semisal object yang akan kita gerakkan berada di posisi A. Kita ingin menggerakkan object ini ke titik B.

Pertama kali, simpan titik tujuan ini, koordinat titik B, sebagai atribute dari sang object.

Langkah selanjutnya kita lakukan adalah mengurangkan koordinat titik tujuan dengan koordinat titik awal. Di sini kita akan mendapatkan (non-normalized) vector dari titik awal ke titik tujuan.

@exavolt
exavolt / lineintersection.as
Created February 24, 2012 08:45 — forked from painquin/lineintersection.as
Line segment intersection in AS3
// ported from http://alienryderflex.com/intersect/
public static function LineIntersection(a:Point, b:Point, c:Point, d:Point):Point
{
var distAB:Number, cos:Number, sin:Number, newX:Number, ABpos:Number;
if ((a.x == b.x && a.y == b.y) || (c.x == d.x && c.y == d.y)) return null;
if ( a == c || a == d || b == c || b == d ) return null;
b = b.clone();
@exavolt
exavolt / sdl2_opengl.c
Created April 11, 2012 16:36
Very basic SDL2 OpenGL application
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
@exavolt
exavolt / go-git-log.go
Last active August 21, 2019 04:26
Nothing
package main
import (
"fmt"
"path/filepath"
"strings"
"gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
@exavolt
exavolt / color_choice_bar.dart
Last active July 13, 2020 05:07
A color choice bar similar to Keep's and Instagram's
//
import 'package:flutter/material.dart';
class ColorChoiceController extends ValueNotifier<ColorChoiceValue> {
ColorChoiceController([int index])
: super(index != null ? ColorChoiceValue(index) : null);
Color get color => this.value?.color;
@exavolt
exavolt / theme_mode_app.dart
Last active September 29, 2020 18:36
Switch theme mode (system, light, dark) dynamically
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
// Wrap your application instance with this class.
//
// class MyApp extends StatelessWidget {
// // This widget is the root of your application.
// @override
// Widget build(BuildContext context) {
// return ThemeModeApp((BuildContext context, ThemeMode themeMode) {