Skip to content

Instantly share code, notes, and snippets.

View lf94's full-sized avatar
🏔️
Hey how's it going

49fl lf94

🏔️
Hey how's it going
View GitHub Profile
@lf94
lf94 / moe_insert.c
Created May 14, 2015 02:59
GNU Moe's buffer data management
void Basic_buffer::add_line( const char * const buf, const int len )
{
data.back().append( buf, len );
if( data.back().size() && data.back()[data.back().size()-1] == '\n' )
{
if( data.size() >= data.capacity() && data.size() >= 10000 )
data.reserve( data.size() + ( data.size() / 10 ) );
data.push_back( std::string() );
}
}
@lf94
lf94 / sam_insert.c
Created May 14, 2015 03:00
Plan 9 Sam's buffer data management
void
bufinsert(Buffer *b, uint q0, Rune *s, uint n)
{
uint i, m, t, off;
if(q0 > b->nc)
panic("internal error: bufinsert");
while(n > 0){
setcache(b, q0);
@lf94
lf94 / ex-vi_insert.c
Created May 14, 2015 03:02
Bill Joy's Ex/Vi's buffer data management
/*
* Append after line a lines returned by function f.
* Be careful about intermediate states to avoid scramble
* if an interrupt comes in.
*/
int
append(int (*f)(void), line *a)
{
register line *a1, *a2, *rdot;
int nline;
@lf94
lf94 / gtktextbtree_insert.c
Created May 14, 2015 03:03
GNOME GtkTextView/GtkTextBuffer's buffer data management
void
_gtk_text_btree_insert (GtkTextIter *iter,
const gchar *text,
gint len)
{
GtkTextLineSegment *prev_seg; /* The segment just before the first
* new segment (NULL means new segment
* is at beginning of line). */
GtkTextLineSegment *cur_seg; /* Current segment; new characters
* are inserted just after this one.
@lf94
lf94 / emacs_insert.c
Created May 14, 2015 03:03
GNU Emac's buffer data management
void
insert_1_both (const char *string,
ptrdiff_t nchars, ptrdiff_t nbytes,
bool inherit, bool prepare, bool before_markers)
{
if (nchars == 0)
return;
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
nchars = nbytes;
@lf94
lf94 / cellbuffer_insert.c
Created May 15, 2015 05:35
Scintilla's CellBuffer buffer's data management
void CellBuffer::BasicInsertString(int position, const char *s, int insertLength) {
if (insertLength == 0)
return;
PLATFORM_ASSERT(insertLength > 0);
substance.InsertFromArray(position, s, 0, insertLength);
style.InsertValue(position, insertLength, 0);
int lineInsert = lv.LineFromPosition(position) + 1;
bool atLineStart = lv.LineStart(lineInsert-1) == position;
@lf94
lf94 / timeclock.awk
Created June 10, 2015 08:40
Calculate total hours for an Emacs timeclock log.
function toDateTime(date, time) {
gsub(/\//, " ", $2)
awkDate = $2
gsub(/:/, " ", $3)
awkTime = $3
return mktime(awkDate " " awkTime)
}
/^i / {
clockIn = toDateTime($2, $3)
@lf94
lf94 / 1.js
Last active August 29, 2015 14:24
Iterations of Badge.js
/*
A widget that will appear when the screen reaches a certain size. Allows opening and closing of a sidebar.
100% pure, vanilla JavaScript and CSS.
*/
(function(){
var Badge = function(target, placement) {
var self = this;
this.target = target;
this.placement = placement;
MusicSelectData:
.db WaterMusic, GroundMusic, UndergroundMusic, CastleMusic
.db CloudMusic, PipeIntroMusic
GetAreaMusic:
lda OperMode ;if in title screen mode, leave
beq ExitGetM
lda AltEntranceControl ;check for specific alternate mode of entry
cmp #$02 ;if found, branch without checking starting position
beq ChkAreaType ;from area object data header
@lf94
lf94 / brainfuck.hs
Created September 12, 2015 14:33
Brainfuck interpreter in Haskell (No Input/Output support yet)
{-
A brainfuck interpreter in Haskell.
An exercise to flex these FP muscles.
-}
module Main where
import Debug.Trace
import Control.Monad.Trans.State.Lazy