Skip to content

Instantly share code, notes, and snippets.

View DanGe42's full-sized avatar

Daniel Ge DanGe42

View GitHub Profile
@DanGe42
DanGe42 / context_demo.c
Created October 25, 2013 03:14
A non-trivial example of how to use user contexts for trivial scheduling.
#include <ucontext.h>
#include <sys/types.h>
#include <sys/time.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <poll.h>
/* ucontext sample program

Recipe for Brazilian Brigadeiros

Kika is one of our product managers, and you might know her as the Kika of Kika’s Treats, the San Francisco company whose chocolate-covered caramelized cookies used to sit on our shelves. Shortly after our Valencia Street café opened its doors in 2010 she did a pop-up in our pastry kitchen, and we’ve been dreaming of the baked goods and confections she made when she was behind the stoves ever since. Her Brazilian cheese bread? Legendary. Her fresh fig and chocolate ganache galette? We’d do anything for a crumb. But every time we’ve thought about her chocolatey, creamy brigadeiros (pronounced bree-guh-DAY-rows) over the years, we’ve gotten more than a little swoony.

Let us explain.. Brigadeiros are an extremely popular truffle-like confection from Kika’s native Brazil that everyone makes at home for parties or special occasions. They’re as popular as chocolate-chip cookies. Usually they’re overwhelmingly dense and sweet from concentrated sweetened condensed milk and sweet c

@DanGe42
DanGe42 / components.external-link.js
Last active August 7, 2019 21:09
A trailing whitespace riddle
@DanGe42
DanGe42 / controllers.application.js
Last active July 22, 2019 21:38
Route hooks evaluation order
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@DanGe42
DanGe42 / controllers.application.js
Last active July 13, 2019 01:29
belongsTo test
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember belongsTo test'
});
function getWhateverObject() {
return Promise.resolve({ getBooleanValue() { return true; } })
}
async function iNeedThisBoolean() {
const someObject = await getWhateverObject();
const fWhatever = someObject.getBooleanValue();
if (fWhatever) {
console.log("true");
} else {
@DanGe42
DanGe42 / main.go
Created September 20, 2016 05:59
A go/crypto + protobuf sample
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"io"
@DanGe42
DanGe42 / command.sh
Created July 13, 2018 07:46
60fps timelapse scripts
ffmpeg \
-framerate 60 \ # input framerate = 60fps
-start_number 0000 \ # start at frame_0000.JPG
-i frame_%04d.JPG \ # image filename template
-s 2560x1440 \ # resolution
-r 60 \ # output framerate = 60fps
-crf 17 \ # constant rate factor (17-28 is a "sane" range; lower is less lossy)
-vcodec libx264 \
-pix_fmt yuv420p \ # Support Quicktime playback
timelapse.mp4
#include <ucontext.h>
#include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#define STACKSIZE 4096
void f(){
@DanGe42
DanGe42 / broken_context.c
Created October 25, 2013 03:16
Why is this one broken? Answer (use a base64 decoder): Zm9vX2NvbnRleHQgbmVlZHMgdG8gYmUgcmVpbml0aWFsaXplZCB3aXRoIG1ha2Vjb250ZXh0IG9uY2UgZm9vIHJldHVybnMgYW5kIGNhdXNlcyB0aGUgY29udGV4dCBzd2l0Y2ggdG8gdWNfbGluaw==
#include <stdlib.h>
#include <stdio.h>
#include <ucontext.h>
#define STACKSIZE 4096
ucontext_t foo_context, main_context;
void foo() {
printf("Executing foo!\n");