Skip to content

Instantly share code, notes, and snippets.

// lambda syntax; construction & call
int x = 0;
int y = 10;
[x, &y] (int z) { return x + (++y) + (++z); } (5);
// desugared
struct __lambda1 {
int x;
int &y;
from PIL import Image
from urllib.request import urlopen
from urllib.parse import quote_plus
import json
import io
import re
from random import choice
def first(xs):
for x in xs:
import sys
if sys.version_info[0] == 3:
from io import StringIO
else:
from cStringIO import StringIO
def replace_entities(text, grouped_entities, **replacers):
entities = []
@Garciat
Garciat / twitter_authorize.py
Created October 1, 2014 21:00
requires pip packages: requests, requests_oauthlib
import requests
from requests_oauthlib import OAuth1Session
client_key = ''
client_secret = ''
request_token_url = 'https://api.twitter.com/oauth/request_token'
oauth = OAuth1Session(client_key, client_secret=client_secret)
fetch_response = oauth.fetch_request_token(request_token_url)
@Garciat
Garciat / twitter_search.py
Last active August 29, 2015 14:07
requires pip packages: requests
import requests
import base64
import json
import sys
def log(msg):
sys.stderr.write(msg)
sys.stderr.write('\n')
client_key= ''
// compile with: gcc openmp.c -o openmp -std=c11 -O3 -Wall -fopenmp
#include <stdio.h>
#include <stdlib.h>
typedef int num;
int main(int argc, char *argv[]) {
int n = 20000;
int m = 20000;
#include <iostream>
// ---
#include <array>
#include <utility>
template <typename T>
using c_array = T[];
#include <type_traits>
#include <tuple>
#include <functional>
template <typename FType>
struct function_traits;
template <typename RType, typename... ArgTypes>
struct function_traits<RType(ArgTypes...)> {
using arity = std::integral_constant<size_t, sizeof...(ArgTypes)>;
@Garciat
Garciat / curry.cpp
Last active August 29, 2015 14:12
Function currying in C++14 (function_traits.cpp: https://gist.github.com/Garciat/cafe27d04cfdff0e891e)
#include <type_traits>
#include <utility>
#include <tuple>
#include "function_traits.cpp"
// ---
template <typename Args, typename Params>
struct apply_args;
struct meow {
static int defaults;
static int copies;
static int moves;
static int destroys;
static void report() {
std::cout << "defaults: " << defaults << std::endl;
std::cout << "copies: " << copies << std::endl;
std::cout << "moves: " << moves << std::endl;