Skip to content

Instantly share code, notes, and snippets.

View jc4p's full-sized avatar

Kasra Rahjerdi jc4p

View GitHub Profile
@jc4p
jc4p / Hello.tsx
Created January 6, 2017 18:05
TypeScript 2.1.4 + Webpack 2.0 beta + Preact. Uses babel and ts-loader to convert to ES5/ES6/whatever-you-want bundle.
// src/components/Hello.tsx
import { h, Component, render } from "preact";
export interface HelloProps { compiler: string; framework: string; }
export default class Hello extends Component<HelloProps, undefined> {
constructor(props: any) {
super(props);
// #TODO: fetch() from the API, or set up a ServiceWorker to do so.
@jc4p
jc4p / photo organizer.md
Last active January 4, 2017 10:53
I want a open photo collection organizer. I don't want to build this but I will if I have to

Photo Collection Manager

Local electron app + PWA front end for viewing local files on your phone if on local wifi

No consolidated servers, but everything is OSS and PWA app can be set up on your own server to also use to view images stored in cloud

Back up to your own cloud

Import from any cloud / the Windows OS X Linux box it's running on / Lightroom / etc

<p class="category col two"><em>{{ category.title }}</em></p>
<ul class="project-list col seven">
{% foreach post in category.posts %}
<li>
<div class="thumbnail col two">
<img src="{{ post.thumb }}" alt=""></a>
</div>
<div class="summary col two">
<p><a href="{{ url_for(post) }}">{{ post.title }}</a></p>
<p><em>{{ post.date|relative }}</em></p>
/**
* Calculates if the given textColor is readable when laid ontop of the given backgroundColor.
*
* http://www.seas.upenn.edu/~cse400/CSE400_2012_2013/reports/01_report.pdf
*/
public static boolean isTextReadable(int backgroundColor, int textColor) {
double brightnessBackground = (299*Color.red(backgroundColor) + 587*Color.green(backgroundColor) + 114*Color.blue(backgroundColor)) / 1000.0;
double brightnessText = (299*Color.red(textColor) + 587*Color.green(textColor) + 114*Color.blue(textColor)) / 1000.0;
double brightnessDelta = Math.abs(brightnessBackground - brightnessText);
@jc4p
jc4p / MainActivity.java
Created February 5, 2015 20:56
Double DrawerLayout bug
package com.kasra.androidsandbox;
import android.os.Bundle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
@jc4p
jc4p / gif.py
Last active August 29, 2015 14:11
Turns a SE holiday party photo booth pic into a GIF
from PIL import Image
from moviepy.editor import ImageSequenceClip
from os import remove
import sys
# The width and height for each picture in the x2-size image.
pic_size = 485, 368
def get_frame(img, x, y):
return img.crop((x, y, x + pic_size[0], y + pic_size[1]))
@jc4p
jc4p / uber.js
Created November 2, 2014 02:29
Check how much you've spent on Uber
// Run this on the JS console when logged into https://riders.uber.com/trips
var currentPage=1;var spent=0;var gotPage=function e(t){if($(t).find("td.text--right").length===0){console.log("All Done! You've spent: "+spent);return}$("td.text--right").each(function(e,t){spent+=parseInt($(this).children().remove().end().text().substring(1))});currentPage+=1;$.get("https://riders.uber.com/trips?page="+currentPage,e);console.log("Loading page "+currentPage)};$.get("https://riders.uber.com/trips?page="+currentPage,gotPage)
@jc4p
jc4p / simplecv_test.py
Created October 9, 2014 00:27
Detect eyes, mouth, and ears from a camera.
from SimpleCV import Camera, Display, HaarCascade, Image, Color
cam = Camera()
display = Display()
cascadeEye = HaarCascade("eye")
cascadeLeftEar = HaarCascade("left_ear")
cascadeRightEar = HaarCascade("right_ear")
cascadeMouth = HaarCascade("mouth")
@jc4p
jc4p / option3.java
Last active August 29, 2015 14:02 — forked from bnickel/option3.java
// Good idea or Bad idea?
// Lets say you have to call some API with lots of parameters that you don't control
// Like this http://developer.android.com/reference/android/text/StaticLayout.html#StaticLayout(java.lang.CharSequence, int, int, android.text.TextPaint, int, android.text.Layout.Alignment, float, float, boolean, android.text.TextUtils.TruncateAt, int)
// Do you prefer Option #1 or Option #2? Is Option #2 a terrible idea?
// I suppose Option #3 could be to wrap it in a Builder
class Foo {

Keybase proof

I hereby claim:

  • I am jc4p on github.
  • I am kasra (https://keybase.io/kasra) on keybase.
  • I have a public key whose fingerprint is CC17 5E08 A771 3140 8965 5951 57CB 049F F2B5 C9D0

To claim this, I am signing this object: