Skip to content

Instantly share code, notes, and snippets.

@fmela
fmela / stacktrace.cxx
Last active September 22, 2023 10:58
A C++ function that produces a stack backtrace with demangled function & method names.
/*
* Copyright (c) 2009-2017, Farooq Mela
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@kitek
kitek / gist:1579117
Created January 8, 2012 17:50
NodeJS create md5 hash from string
var data = "do shash'owania";
var crypto = require('crypto');
crypto.createHash('md5').update(data).digest("hex");
@sandys
sandys / scalafun.md
Created September 24, 2012 18:06
Notes for Scala functional programming coursera
  • if CBV terminates, then so does CBN - since CBN will evaluate less than or equal parameters than CBV
  • CBV avoids repeated recomputation of values
  • force scala to do CBN, by defining def fun(x:Int, y:=>Int)
  • disjunction and conjunction (&& and ||) are short-circuit operators - the right side will only be evaluated in certain cases.
  • in certain cases like
    if(r==0)
      return 1
    there is an error Scala: type mismatch; found : Unit required: Boolean
    • this happens because you have to have an else clause, otherwise the type checker doesn't know what the return type is when it's not the case
  • return fn(a-1) is tail recursive but return n * fn(a-1) is not
@ozh
ozh / new empty git branch.md
Last active May 29, 2024 00:00
Create a new empty branch in Git
$ git checkout --orphan NEWBRANCH
$ git rm -rf .

--orphan creates a new branch, but it starts without any commit. After running the above command you are on a new branch "NEWBRANCH", and the first commit you create from this state will start a new history without any ancestry.

You can then start adding files and commit them and they will live in their own branch. If you take a look at the log, you will see that it is isolated from the original log.

@ssmereka
ssmereka / server.js
Last active August 12, 2021 08:50
Quick example of a Node.JS Server. You can use this to get started learning node.js.
/**
* Example Node.JS Application
* Shows just how easy node can be.
*/
/* Install Node.JS and NPM
* On Ubuntu:
sudo apt-get update -y --force-yes -qq
sudo apt-get install -y --force-yes -qq python-software-properties > /dev/null 2>&1
@gitaarik
gitaarik / git_submodules.md
Last active July 26, 2024 13:44
Git Submodules basic explanation

Git Submodules basic explanation

Why submodules?

In Git you can add a submodule to a repository. This is basically a repository embedded in your main repository. This can be very useful. A couple of usecases of submodules:

  • Separate big codebases into multiple repositories.
@lttlrck
lttlrck / gist:9628955
Created March 18, 2014 20:34
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@wrobstory
wrobstory / redshift.sql
Created November 5, 2014 16:53
Redshift debugging queries
-- Gets all queries for a given date range
select starttime, endtime, trim(querytxt) as query
from stl_query
where starttime between '2014-11-04' and '2014-11-05'
order by starttime desc;
-- Gets all queries that have been aborted for a given date range
select starttime, endtime, trim(querytxt) as query, aborted
from stl_query
where aborted=1
@montanaflynn
montanaflynn / streamer.js
Created January 27, 2015 19:38
Streaming a response with Express.js
var express = require('express')
var app = express()
app.listen(1337)
app.all('/stream/:chunks', function (req, res, next) {
res.writeHead(200, {
'Content-Type': 'text/plain',
@jeffjohnson9046
jeffjohnson9046 / git-ignore.sh
Created August 11, 2015 21:02
Remove unwanted files from a git repo AFTER adding a .gitignore. The files will remain on disk.
## I just ran into this after initializing a Visual Studio project _before_ adding a .gitignore file (like an idiot).
## I felt real dumb commiting a bunch of files I didn't need to, so the commands below should do the trick. The first two commands
## came from the second answer on this post: http://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files
# See the unwanted files:
git ls-files -ci --exclude-standard
# Remove the unwanted files:
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached